lalabored Posted June 10, 2007 Share Posted June 10, 2007 I get this error... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in readpm.php on line 22 With this code $q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1"; $rs = mysql_query($q); $rscount = mysql_num_rows($rs); Can someone tell me what's wrong? Quote Link to comment Share on other sites More sharing options...
needy Posted June 10, 2007 Share Posted June 10, 2007 hi, i also get this error sometimes. in my case, i get this error when my SQL statement is wrong or when my database is empty. so you too check that. try printing the select statement and run same statement directly in the database. Quote Link to comment Share on other sites More sharing options...
kritical Posted June 10, 2007 Share Posted June 10, 2007 $q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1"; $rs = mysql_query($q); $rscount = mysql_num_rows($rs); The major problem I can see is that you're not checking to make sure that the mysql_query() function executed cleanly, when it doesn't $rs will be set to false. You could try changing it to something like this: $q = "SELECT * FROM pm_messages WHERE id='$id' and to_id='$memberid' LIMIT 1"; $rs = mysql_query($q); if (!$rs) { die("Could not query the database!"); } $rscount = mysql_num_rows($rs); The problem is that this is quite messy and I'm assuming that you haven't checked to make sure your mysql_connect and mysql_select_db functions have been executed cleanly. I've written a short example on how to do the basics of this: http://kritical.info/?p=8 I've written an example of how to do this a bit cleaner, although my example still uses die() if there is an error you could quite easily change this to your hearts content, I hope this helps, cheers... Quote Link to comment Share on other sites More sharing options...
lalabored Posted June 10, 2007 Author Share Posted June 10, 2007 Ah! I checked to see if $rs returned false and it did. I found my mistake I think. I put the variables in single quotes while they are integers so I guess that messed it up. Thank you for you help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.