Jump to content

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resourc


JakeSilver

Recommended Posts

I am recieving the following error =(

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on line 71

 

70        $sql = mysql_query("SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1"); 
71        $login_check = mysql_num_rows($sql); 
72        $inf = mysql_fetch_object($sql); 

 

Is this due to the structure of my query?

 

Thanks in Advanced ;D

Try the following

 

$sql = "SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1";

$result = mysql_query($sql);

$count = mysql_num_rows($result);

   

if ($count == 1)

{

//Put what you wan't to do here

}

else

{

echo "Error! Failed to log you in.";

}

Always check to see if the query succeeds before doing any other MySQL operations:

<?php
$sql = "SELECT * FROM users WHERE username='$username' AND password='$password' AND activated='1' LIMIT 1";
$result = mysql_query($sql) or die("Problem with the query: $sql<br>" . mysql_error());
?>

 

If an error prints, it should give you a hint as to what is wrong.

 

Ken

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.