i have an error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
zyklon
Forum Commoner
Posts: 49
Joined: Mon Jul 31, 2006 7:14 pm
Location: MA, USA

i have an error

Post by zyklon »

mysql_num_rows(): supplied argument is not a valid MySQL result resource is the error, the line and the supplied argument are the following 2 lines:

Code: Select all

$result = mysql_query("SELECT * FROM events WHERE usertoid='$userd[id]'");
if(mysql_num_rows($result)) {
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I hope you don't expect us to fix your car if you only bring us the hood...
User avatar
zyklon
Forum Commoner
Posts: 49
Joined: Mon Jul 31, 2006 7:14 pm
Location: MA, USA

Post by zyklon »

wut else would you like to know?? the connection to the db is up, it is accessing real things in the db.... that was line 40, and 39, the error places...
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Echo the query. I'll bet that it doesn't look like what you expect...

also, the query should look like

Code: Select all

"SELECT * FROM `events` WHERE usertoid='{$userd['id']}'";
or

Code: Select all

'SELECT * FROM `events` WHERE usertoid="' . $userd['id'] . '"';
Adding error checking is also good...

for debugging you can use 'or die', but use proper error reporting on the production server

Code: Select all

$result = mysql_query(query) or die('Mysql Error: ' . mysql_error());
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Post by Oren »

Unless 'id' is a constant, but I bet it isn't. If it is then I'll never code PHP again :P
User avatar
zyklon
Forum Commoner
Posts: 49
Joined: Mon Jul 31, 2006 7:14 pm
Location: MA, USA

Post by zyklon »

its workeed for me b4 the other way... but i'll give both a try


edit:i pugged the 1st one in and it worked


thank you.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You may want to search the PHP manual for array handling, strings and concatenation.
Post Reply