Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Thu Aug 22, 2002 12:43 pm
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.
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Thu Aug 22, 2002 12:46 pm
You probably need to quote $userNAME and $userPASS like
Code: Select all
$result=mysql_query("SELECT * FROM mytable WHERE username='$userNAME' AND userpass='$userPASS'");
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Thu Aug 22, 2002 12:51 pm
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.
nielsene
DevNet Resident
Posts: 1834 Joined: Fri Aug 16, 2002 8:57 am
Location: Watertown, MA
Post
by nielsene » Thu Aug 22, 2002 1:00 pm
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?
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Thu Aug 22, 2002 1:06 pm
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.
Gen-ik
DevNet Resident
Posts: 1059 Joined: Mon Aug 12, 2002 7:08 pm
Location: London. UK.
Post
by Gen-ik » Thu Aug 22, 2002 1:13 pm
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.
volka
DevNet Evangelist
Posts: 8391 Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger
Post
by volka » Thu Aug 22, 2002 1:19 pm
ah, so it's a heisenbug: You cannot know both: why or when it occurs