Lt_Wolf Posted October 28, 2007 Share Posted October 28, 2007 I'm making a Hall Of Fame for someone's game and im coming across this problem. This is the error messege: QUERY ERROR: 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 '' at line 1 Query was SELECT * FROM userstats WHERE userid= just a note: There are 'userid' rows for both the users and the userstats tables. function hof_strengthg() { global $db,$ir,$c,$userid, $myf; print "Showing the 20 users with the highest strength gain this month<br /> <table width=75% border=1 class='tablejf1'><tr background='http://suburban-assault.net/header.jpg'> <th>Pos</th> <th>User</th><th>Amount</th> </tr>"; $q=$db->query("SELECT u.*,g.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN gangs g ON g.gangID=u.gang WHERE u.user_level != 0 AND u.user_level != 2 $myf ORDER BY us.strGAIN DESC,u.userid ASC LIMIT 20"); $gh=$db->query("SELECT * FROM userstats WHERE userid={$r['userid']}"); $p=0; while($r=$db->fetch_row($q)) { $p++; if($r['userid'] == $ir['userid']) { $t="<b>";$et="</b>"; } else { $t="";$et=""; } print "<tr> <td>$t$p$et</td> <td>$t{$r['gangPREF']} {$r['username']} [{$r['userid']}]$et</td><td>{$gh['strGAIN']}</td> </tr>"; } print "</table>"; } Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/ Share on other sites More sharing options...
trq Posted October 28, 2007 Share Posted October 28, 2007 I don't see anywhere in the function where you define the array $r. Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-379811 Share on other sites More sharing options...
Lt_Wolf Posted October 28, 2007 Author Share Posted October 28, 2007 an obvious mistake, but the error is still showing. New code: ($r is declared in a file included for the Hall Of Fame page) function hof_strengthg() { global $db,$ir,$r,$c,$userid, $myf; print "Showing the 20 users with the highest strength gain this month<br /> <table width=75% border=1 class='tablejf1'><tr background='http://suburban-assault.net/header.jpg'> <th>Pos</th> <th>User</th><th>Amount</th> </tr>"; $q=$db->query("SELECT u.*,g.* FROM users u LEFT JOIN userstats us ON u.userid=us.userid LEFT JOIN gangs g ON g.gangID=u.gang WHERE u.user_level != 0 AND u.user_level != 2 $myf ORDER BY us.strGAIN DESC,u.userid ASC LIMIT 20"); $gh=$db->query("SELECT * FROM userstats WHERE userid={$r['userid']}"); $p=0; while($r=$db->fetch_row($q)) { $p++; if($r['userid'] == $ir['userid']) { $t="<b>";$et="</b>"; } else { $t="";$et=""; } print "<tr> <td>$t$p$et</td> <td>$t{$r['gangPREF']} {$r['username']} [{$r['userid']}]$et</td><td>{$gh['strGAIN']}</td> </tr>"; } print "</table>"; } Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-379863 Share on other sites More sharing options...
Lt_Wolf Posted October 30, 2007 Author Share Posted October 30, 2007 anyone? Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381443 Share on other sites More sharing options...
GingerRobot Posted October 30, 2007 Share Posted October 30, 2007 Well, presumably you are getting a different error now? Since r is defined, the user id is presumably part of the query now? Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381459 Share on other sites More sharing options...
Lt_Wolf Posted October 30, 2007 Author Share Posted October 30, 2007 the error is the same "QUERY ERROR: 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 '' at line 1 Query was SELECT * FROM userstats WHERE userid=" Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381498 Share on other sites More sharing options...
DyslexicDog Posted October 30, 2007 Share Posted October 30, 2007 What do you get when you echo $r['userid']? and I'm pretty new to mysql statements but why are you using curly braces in your select statement? could this work? $gh=$db->query("SELECT * FROM userstats WHERE userid=$r['userid']"); Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381505 Share on other sites More sharing options...
Psycho Posted October 30, 2007 Share Posted October 30, 2007 What does this output to the page: <?php echo "<pre>"; print_r($r); echo "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381513 Share on other sites More sharing options...
teng84 Posted October 30, 2007 Share Posted October 30, 2007 the error is the same "QUERY ERROR: 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 '' at line 1 Query was SELECT * FROM userstats WHERE userid=" obviously empty variable or something like that SELECT * FROM userstats WHERE userid=" <=--- no value in where condition check your variable or print your query Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381516 Share on other sites More sharing options...
Lt_Wolf Posted October 30, 2007 Author Share Posted October 30, 2007 thanks for the help everyone, I have found a solution myself Link to comment https://forums.phpfreaks.com/topic/75097-solved-query-error-but-it-seems-fine/#findComment-381545 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.