Jump to content

[SOLVED] QUERY ERROR, but it seems fine?


Lt_Wolf

Recommended Posts

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

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>";

}

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.