Page 1 of 1
mysql_num_rows Driving me Mad!
Posted: Thu Aug 22, 2002 12:43 pm
by Gen-ik
I've been through as many PHP forum posts as I can to try and sort this out but nothing seems to work!
I get this error...
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result
...from this code...
$result=mysql_query("SELECT * FROM mytable WHERE username=$userNAME AND userpass=$userPASS");
$num_results=mysql_num_rows($result);
if($num_results==0)
{
echo("No results found");
}
else
{
echo("Results found");
}
...can anyone see a problem here?
Thanks.

Posted: Thu Aug 22, 2002 12:46 pm
by nielsene
You probably need to quote $userNAME and $userPASS like
Code: Select all
$result=mysql_query("SELECT * FROM mytable WHERE username='$userNAME' AND userpass='$userPASS'");
Posted: Thu Aug 22, 2002 12:51 pm
by Gen-ik
I've tried that... I've even gone as far as replacing the whole line with the word Banana!
It doesn't even work if I replace the $userNAME and $userPASS with words instead of variables.
Posted: Thu Aug 22, 2002 1:00 pm
by nielsene
Can you check the mysql error log? That should provide more insight into why the query doesn't work. Does mytable exist, does it have fields named username and password. Does the user you are connecting as have permission to select from that table? Do you have other queries that work?
Posted: Thu Aug 22, 2002 1:06 pm
by Gen-ik
I can write to the database fine.. I can add a new username and userpass into the database and it shows up ok.
All I'm trying to do is check is username & userpass exsist in the database for a simple log-on script.
Posted: Thu Aug 22, 2002 1:13 pm
by Gen-ik
STOP PRESS!
I now works fine!!! I don't know why or how it's working but it is.. and I haven't changed anything.
Thanks for the help anyway.
Posted: Thu Aug 22, 2002 1:19 pm
by volka
ah, so it's a heisenbug: You cannot know both: why or when it occurs
