Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.