0
<?PHP

    $time = $_POST['Time'];//The things in the [] can be anything you want, but remember these for later 
    $xp = $_POST['X'];  

    if($time <= 0) 
        $time = 0; 

    if($xp <= 0) 
        $xp = 0;  

    $db_handle = mysql_connect($server, $user_name, $pass_word); 
    $db_found = mysql_select_db($database, $db_handle);  

    if ($db_found) { 

        $SQL = "SELECT * FROM table1 WHERE Script = MyScript";//Or whatever you called your table and script 
        $result = mysql_query($SQL);

            if($result){ 
            while ($db_field = mysql_fetch_assoc($result)){ 

                        $time = $db_field['Time'] + $time; 
                        $xp = $db_field['XP'] + $xp;             

                    } 

            $SQL = "UPDATE `table1` SET  `XP` =  '".$xp."', `Time` =  '".$time."' WHERE `Script` = MyScript";//You need to put all of your variables in this. 
            $result = mysql_query($SQL); 
            if($result) 
                        print "True"; 
                    else 
                        print "False"; 

            }else 
                    print "Table not found";  

        }else 
            print "Database not found";  

?>  

So this is the PHP I'm running. It should work as it does for others, except it says the table isn't found?
Heres the database:

http://i.imgur.com/TRTZn.png

The user associated with the db has full privaledges etc.

Any reason it wont work? thanks

3
Contributors
11
Replies
13
Views
4 Years
Discussion Span
Last Post by bradly.spicer
Featured Replies
  • 1
    diafol 3,720   4 Years Ago

    You've got output before the header. It's probably whitespace as it seems to be occurring on line 1. From your code - you seem to have a space before the <?PHP Read More

0
print "Table not found";

This isn't true. Just because you've made that the error message does not mean that it can't find the table. Your problem is that the Query has not returned a resource as it's probably mashed to buggery. Try:

$SQL = "SELECT * FROM table1 WHERE Script = 'MyScript'";

Also your next sql:

$SQL2 = "UPDATE `table1` SET  `XP` =  '$xp', `Time` =  '$time' WHERE `Script` = 'MyScript'";
0

Well is the person running this page on his own server? Also, did he change "table1" to what ever the table name is, in the SQL statement?

0

Thanks Diafol, That worked and started returning values as true.

Now for the next challege. I followed his tutorial further and tried to break it up to make it easier to read.

Warning: Cannot modify header information - headers already sent by (output started at /home/xtrapsp/public_html/ollyisafag/Ollyiswrong/index.php:1)

Weird thing is, It's not allowing it to modify header information?

 <?PHP  

    $user_name = "username";  //Username for the account you created earlier 
    $pass_word = "password";  //Password for the account you created earlier 
    $database = "Xtrapsp_Statsdb";  //The name of the database you created earlier 
    $server = "localhost";  

header("Content-type: image/png"); 

function formatMilliseconds($milliseconds) {
        $seconds = floor($milliseconds / 1000);
        $minutes = floor($seconds / 60);
    $hours = floor($minutes / 60);
    $days = floor($hours / 24);
    $milliseconds = $milliseconds % 1000;
        $seconds = $seconds % 60;
    $minutes = $minutes % 60;
    $hours = $hours % 24;

        if($days == 0){
        $format = '%uhours, %02uminutes and %02u seconds';
            $time = sprintf($format, $hours, $minutes, $seconds);
            return rtrim($time, '0');
    }else{
        $format = 'Úys, %uhours, %02uminutes and %02u seconds';
            $time = sprintf($format, $days, $hours, $minutes, $seconds);
            return rtrim($time, '0');
    }

}

function imagettftextshadow($image, $size, $angle, $x, $y, $color, $fontfile, $text) { 
      imagettftext($image, $size, $angle, $x + 1, $y + 1, imagecolorallocate($image, 0, 0, 0), $fontfile, $text); 
      imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text); 
}    

$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);


if ($db_found) {    

    $SQL = "SELECT * FROM table1 WHERE Script = 'MyScript'";   
    $result = mysql_query($SQL);
    if($result){                        
        while ($db_field = mysql_fetch_assoc($result)){

            $xp = $db_field['XP'];
            $time = $db_field['Time'];
        }

        putenv("GDFONTPATH=".realpath("."));   

        $img = imagecreatefrompng("sig.png"); 

        $color["yellow"] = imagecolorallocate( $img, 255, 255, 0 ); 
        $color["white"] = imagecolorallocate( $img, 255, 255, 255 ); 
        $color["green"] = imagecolorallocate( $img, 0, 255, 0 ); 
        $color["orange"] = imagecolorallocate( $img, 254, 179, 0 ); 
        $color["purple"] = imagecolorallocate( $img, 128, 0, 128 ); 
        $color["dblue"] = imagecolorallocate( $img, 37, 84, 199 ); 

        imagettftextshadow($img, 20, 0, 10, 23, $color["dblue"], "sans.ttf", "MyScript"); 
        imagettftextshadow($img, 12, 0, 10, 70, $color["orange"], "sans.ttf", "Time Run: "); 
        imagettftextshadow($img, 12, 0, 90, 70, $color["purple"], "sans.ttf", formatMilliseconds($time * 1000)); 

        imagepng($img); 
        imagedestroy($img);
    }else
                print "False";    

}
else 
    print "DB not Found, please report this";
    ?>

Edited by bradly.spicer

0

Scrap that, The only result i'm getting is False. Revision code:

 <?PHP

function formatMilliseconds($milliseconds) {
        $seconds = floor($milliseconds / 1000);
        $minutes = floor($seconds / 60);
    $hours = floor($minutes / 60);
    $days = floor($hours / 24);
    $milliseconds = $milliseconds % 1000;
        $seconds = $seconds % 60;
    $minutes = $minutes % 60;
    $hours = $hours % 24;

        if($days == 0){
        $format = '%uhours, %02uminutes and %02u seconds';
            $time = sprintf($format, $hours, $minutes, $seconds);
            return rtrim($time, '0');
    }else{
        $format = 'Úys, %uhours, %02uminutes and %02u seconds';
            $time = sprintf($format, $days, $hours, $minutes, $seconds);
            return rtrim($time, '0');
    }

}

function imagettftextshadow($image, $size, $angle, $x, $y, $color, $fontfile, $text) { 
      imagettftext($image, $size, $angle, $x + 1, $y + 1, imagecolorallocate($image, 0, 0, 0), $fontfile, $text); 
      imagettftext($image, $size, $angle, $x, $y, $color, $fontfile, $text); 
}

$user_name = "username";  //Username for the account you created earlier 
$pass_word = "password";  //Password for the account you created earlier 
$database = "database";  //The name of the database you created earlier 
$server = "localhost";     

$db_handle = mysql_connect($server, $user_name, $pass_word);
$db_found = mysql_select_db($database, $db_handle);


if ($db_found) {    

    $SQL = "SELECT * FROM 'table1' WHERE `ID` = 1";   
    $result = mysql_query($SQL);
    if($result){                        
        while ($db_field = mysql_fetch_assoc($result)){

            $xp = $db_field['XP'];
            $time = $db_field['Time'];
        }

        header("Content-type: image/png");
        putenv("GDFONTPATH=".realpath("."));   

        $img = imagecreatefrompng("sig.png"); 

        $color["yellow"] = imagecolorallocate( $img, 255, 255, 0 ); 
        $color["white"] = imagecolorallocate( $img, 255, 255, 255 ); 
        $color["green"] = imagecolorallocate( $img, 0, 255, 0 ); 
        $color["orange"] = imagecolorallocate( $img, 254, 179, 0 ); 
        $color["purple"] = imagecolorallocate( $img, 128, 0, 128 ); 
        $color["dblue"] = imagecolorallocate( $img, 37, 84, 199 ); 

        imagettftextshadow($img, 20, 0, 10, 23, $color["dblue"], "sans.ttf", "MyScript"); 
        imagettftextshadow($img, 10, 0, 205, 23, $color["green"], "sans.ttf", "Version: 1"); 
        imagettftextshadow($img, 12, 0, 10, 50, $color["orange"], "sans.ttf", "XP Gained: "); 
        imagettftextshadow($img, 12, 0, 90, 50, $color["purple"], "sans.ttf", number_format($xp)); 
        imagettftextshadow($img, 12, 0, 10, 70, $color["orange"], "sans.ttf", "Time Run: "); 
        imagettftextshadow($img, 12, 0, 90, 70, $color["purple"], "sans.ttf", formatMilliseconds($time * 1000)); 

        imagepng($img); 
        imagedestroy($img);
    }else
                print "False";    

}
else 
    print "DB not Found, please report this";

?>

0
$SQL = "SELECT * FROM 'table1' WHERE `ID` = 1";

You don't put table names in single quotes - use backticks instead as you've done for `ID`.

$SQL = "SELECT * FROM `table1` WHERE `ID` = 1";
0

Such a silly mistake!

Thanks Diafol, However since doing that I have encountered MORE problems. This is one I fixed previously but since putting table back into those backticks rather than quotes it has come back.

Warning: Cannot modify header information - headers already sent by (output started at /home/xtrapsp/public_html/testphp/PascaltoPHP/index.php:1) in /home/xtrapsp/public_html/testphp/PascaltoPHP/index.php on line 59
‰PNG  IHDR©xÇ[š2 IDATxœíw|TÅÚÇ[³Énzß $¤Š€°ˆ€Bè FšR.Š€¸è«ØîU,pU°!‚(Eª´‰„v¥PC!$aÓ“MÛl¶Ÿ÷Ùœlv³›çûásžyÎœggŸ<3Ïœ€B¡P( …B¡P(”‡Î)G<}ŒË(ùíMÕí#öôÄÒÒ¸Èqñé¥ %§ïÈ&¾Xê5É- 7ß-ˆÃåuuºÚ› e¿Õ$µÊ;ªÊ1B÷0é€OÚšÛGgÞÃj)Ê_¾óªB\¾ˆ18\¾À-ȦoçÆÄáphª³ïÈ ÷Ð=_åò\4J|‘/_äë+p....

This is what comes up on the page now

I assume that this is happening because it's trying to read the image as text, hence the symbols etc and the header can't change it into a PNG file.

The header being:

header("Content-type: image/png");
putenv("GDFONTPATH=".realpath(".")); 

line 50-51

Edited by bradly.spicer

1

You've got output before the header. It's probably whitespace as it seems to be occurring on line 1. From your code - you seem to have a space before the <?PHP

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.