Jump to content

Warning: mysql_fetch_array():


grlayouts

Recommended Posts

Hey guys, i'm sure this is simple  i have a script that always brings back the same error and I beleive it's going to be the php version im on the code is

 

function check_user( $u ) {

$res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`=$u");
list($total_rows) = mysql_fetch_array($res) or die (mysql_error());

if( $total_rows > 0 ) return true;
else return false;

}

 

the error is

 


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bofs/public_html/thief/inc/userinc.php on line 10
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

 

any idea's

Link to comment
https://forums.phpfreaks.com/topic/225713-warning-mysql_fetch_array/
Share on other sites

Looking at the query:

SELECT * FROM `usertable` WHERE `userid`=

 

It looks like $u doesn't contain any data which causes the query to fail. If you echo $u before querying the database, does it show anything?

 

...
function check_user( $u ) {
    echo "<div>User ID: $u</div>";
    $res = query("SELECT COUNT(*) FROM `usertable` WHERE `userid`=$u");
...

Didn't see the query() function defined in the second post.

 

Where are you getting the value you're passing to the the check_user() function? Have you echoed it to make sure the value is what you'd expect?

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.