dean7 Posted October 2, 2010 Share Posted October 2, 2010 Hi all, I've got a problem with my latest script. I havent tested it or anything as ive got an error saying: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''NoName' at line 1 Not sure where about's the error is in my script or how to sort it: <?php session_start(); include ("includes/config.php"); include ("includes/functions.php"); logincheck(); ini_set ('display_errors', 1); error_reporting (E_ALL); $username = $_SESSION['username']; $fetch = mysql_query("SELECT * FROM users WHERE username='$username'") or die (mysql_error()); $user = mysql_fetch_object($fetch); $caridd = mysql_query("SELECT carid FROM users WHERE username='$username") or die (mysql_error()); $carid = mysql_fetch_object($caridd); $garage = mysql_query("SELECT * FROM garage WHERE owner='$username AND id='$carid->carid'") or die (mysql_error()); $gar = mysql_fetch_object($garage); // Got all the information I need. $time = time() + 300; // Waiting time. (5min) if ($user->foltime > time()){ $left = $user->foltime - time(); echo "<table width='40%' cellpadding='0' align='center' cellspacing='0' border='1' class='table'> <tr> <td class='header' align='center'>Error!</td> </tr> <tr> <td align='center'> You must wait <b>$left seconds</b> before you play Faster Or Slower agian<br /> To do one more often, reset you time by using credits. <br /><br /><a href='credits.php' target='mainFrame'>Reset</a> </td> </tr> </table><br />"; exit(); } if($_POST['submit'] && $_POST['select']){ exit(); } $dbox = $_POST['select']; if ($dbox == '1'){ // Slow'ish Computer. $comspeed = rand(10,50); $rep = rand(1500,10000); $money = rand(2000,15000); $newmoney = $user->money + $money; // New Money $newrep = $user->rep + $rep; // New Rep if ($gar->speed > $comspeed){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $comspeed <br /> You also won £".makecomma($money)." and ".makecomma($rep).""); }elseif ($gar->speed < $comspeed){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $comspeed"); }elseif ($gar->speed == $comspeed){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $comspeed <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option 1 ////////////////////// END OPTION 1 !! if ($dbox == '2'){ // Slow'ish / fast'ish Computer. $cspeed = rand(50,150); $repp = rand(10000,20000); $moneyy = rand(20000,40000); $newmoney1 = $user->money + $money; // New Money $newrep1 = $user->rep + $rep; // New Rep if ($gar->speed > $comspeed){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $cspeed <br /> You also won £".makecomma($moneyy)." and ".makecomma($repp).""); }elseif ($gar->speed < $comspeed){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $cspeed"); }elseif ($gar->speed == $comspeed){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $cspeed <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney1'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep1'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option 2 ////////////////////// END OPTION 2 !! if ($dbox == '3'){ // Slow'ish / fast'ish Computer. $cospeed = rand(150,300); $reep = rand(30000,50000); $moneey = rand(25000,75000); $newmoney11 = $user->money + $money; // New Money $newrep11 = $user->rep + $rep; // New Rep if ($gar->speed > $comspeed){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $cospeed <br /> You also won £".makecomma($moneey)." and ".makecomma($reep).""); }elseif ($gar->speed < $comspeed){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $cospeed"); }elseif ($gar->speed == $comspeed){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $cospeed <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney11'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep11'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option ////////////////////// END OPTION 3 !! if ($dbox == '4'){ // fast'ish Computer. $compspeed = rand(300,400); $reeep = rand(30500,80000); $moneeey = rand(50000,100000); $newmoney22 = $user->money + $money; // New Money $newrep22 = $user->rep + $rep; // New Rep if ($gar->speed > $compspeed){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compspeed <br /> You also won £".makecomma($moneeey)." and ".makecomma($reeep).""); }elseif ($gar->speed < $compspeed){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compspeed"); }elseif ($gar->speed == $compspeed){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $cospeed <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney22'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep22'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option ////////////////////// END OPTION 4 !! if ($dbox == '5'){ // fast Computer. $compuspeed = rand(400,650); $reeepp = rand(80000,100000); $moneeeyy = rand(100000,150000); $newmoney33 = $user->money + $money; // New Money $newrep33 = $user->rep + $rep; // New Rep if ($gar->speed > $compuspeed){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compuspeed <br /> You also won £".makecomma($moneeeyy)." and ".makecomma($reeepp).""); }elseif ($gar->speed < $compuspeed){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compuspeed"); }elseif ($gar->speed == $compuspeed){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $cospeed <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney33'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep33'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option ////////////////////// END OPTION 5 !! if ($dbox == '6'){ // fast Computer. $compuspeeddd = rand(650,800); $reeepp = rand(100000,150000); $moneeeyy = rand(150000,175000); $newmoney44 = $user->money + $money; // New Money $newrep44 = $user->rep + $rep; // New Rep if ($gar->speed > $compuspeeddd){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compuspeeddd <br /> You also won £".makecomma($moneeeyy)." and ".makecomma($reeepp).""); }elseif ($gar->speed < $compuspeeddd){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compuspeeddd"); }elseif ($gar->speed == $compuspeeddd){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $compuspeeddd <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney44'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep44'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option ////////////////////// END OPTION 6 !! if ($dbox == '7'){ // fast Computer. $compuspeedddd = rand(1,5); $reeeppp = rand(120000,170000); $moneeeyyy = rand(200000,250000); $newmoney55 = $user->money + $money; // New Money $newrep55 = $user->rep + $rep; // New Rep if ($gar->speed > $compuspeedddd){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compuspeedddd <br /> You also won £".makecomma($moneeeyyy)." and ".makecomma($reeeppp).""); }elseif ($gar->speed < $compuspeedddd){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $compuspeedddd"); }elseif ($gar->speed == $compuspeedddd){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $compuspeedddd <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney55'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep55'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option ////////////////////// END OPTION 7 !! if ($dbox == '8'){ // fast Computer. $computerrrrrrrrr = rand(1,5); $reeepppyyyyyyyy = rand(120000,170000); $moneeeyyyyyyyyyyy = rand(200000,250000); $newmoney66 = $user->money + $money; // New Money $newrep66 = $user->rep + $rep; // New Rep if ($gar->speed > $computerrrrrrrrr){ // If user is faster echo ("Well done! Your car beat the Computer Car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $computerrrrrrrrr <br /> You also won £".makecomma($moneeeyyyyyyyyyyy)." and ".makecomma($reeepppyyyyyyyy).""); }elseif ($gar->speed < $computerrrrrrrrr){ echo ("Unlucky! Your car wasnt faster than the computer car speed. <br /> Your Car Speed: $gar->speed <br /> Computer Car Speed: $computerrrrrrrrr"); }elseif ($gar->speed == $computerrrrrrrrr){ echo ("Your Speed and the Computer's Speed where the same! <br /> Computer Speed: $computerrrrrrrrr <br /> Your Speed: $gar->speed"); } mysql_query ("UPDATE users SET money = '$newmoney66'") or die (mysql_error()); mysql_query ("UPDATE users SET rep = '$newrep66'") or die (mysql_error()); mysql_query ("UPDATE users SET foltime = '$time'") or die (mysql_error()); } // Option ////////////////////// END OPTION 8 !! ?> <html> <head> <title>Faster Or Slower || SD</title> </title> </head> <body> <form action='' method='POST' name=''> <table width='50%' cellpadding='0' cellspacing='0' border='1' class='table'> <tr> <td class='header' align='center'>Faster Or Lower?</td> </tr> <tr> <td class='omg' align='center'>The Aim:</td> </tr> <tr> <td colspan='2'>The aim of Faster Or Lower is that the person with the fastest car wins, out of you and the Computer. The Computer speeds are random. If your speed of the car your Currently in is faster than the random Computer speed's you win, other wise you lose. Allthough, if yours and the Computers speed's are the same you lose.</td> </tr> <tr> <td><select name='select' size='1' class='dropbox'> <option value='1'>10MPH - 50MPH</option> <option value='2'>50MPH - 150MPH</option> <option value='3'>150MPH - 300MPH</option> <option value='4'>300MPH - 400MPH</option> <option value='5'>400MPH - 650MPH</option> <option value='6'>650MPH - 800MPH</option> </td> </tr> <tr> <td class='header' align='center'>Donators:</td> </tr> <tr> <td><?php if ($user->location == 'Donator Land'){ echo ("option value='7'>Over 5MPH</option> <option value='8'>Over 5MPH</option>"); } ?> </td> </tr> <tr> <td><input name="submit" type="submit" class="button" value="Race!"></td> </tr> </table> </form> </body> </html> Anyone see where it is coming from? Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/214987-error-sql-syntax/ Share on other sites More sharing options...
theITvideos Posted October 2, 2010 Share Posted October 2, 2010 Do a quick print_r($YourSQLvariableName); And this will display what is inside your sql syntax and whats happening inside the query. It will display the output on the top of the screen. Cheers! Quote Link to comment https://forums.phpfreaks.com/topic/214987-error-sql-syntax/#findComment-1118328 Share on other sites More sharing options...
kenrbnsn Posted October 2, 2010 Share Posted October 2, 2010 You're missing the closing quote in two of your 3 queries. When using the "die" clause it's always helpful to echo the query, so you know which query is causing the problem. Ken Quote Link to comment https://forums.phpfreaks.com/topic/214987-error-sql-syntax/#findComment-1118330 Share on other sites More sharing options...
ngreenwood6 Posted October 2, 2010 Share Posted October 2, 2010 also you should be using mysql_real_escape_string() because if any of those variables have a quote in them it will also break the query. Quote Link to comment https://forums.phpfreaks.com/topic/214987-error-sql-syntax/#findComment-1118334 Share on other sites More sharing options...
PFMaBiSmAd Posted October 2, 2010 Share Posted October 2, 2010 Also, why are you writing out/duplicating all that code over and over when the only thing that is changing between them is the calculation of a few values. And using three UPDATE queries when you only need one for all the values. Just calculate the values in a switch/case statement and use common code for everything else. Also, I would put the display_errors/error_reporting code after the first <?php tag and before any lines of code so that any errors that occur in those lines of code (your session_start, include statements, and logincheck..) will also be displayed/reported. Also also, why are you selecting everything from your users table for the current username in one query and then executing another query right after that getting the cardid for that username? You have about 5 times more code than you need and the more code you write the more errors you have to find and fix. Quote Link to comment https://forums.phpfreaks.com/topic/214987-error-sql-syntax/#findComment-1118337 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.