Maniacility Posted February 2, 2008 Share Posted February 2, 2008 I keep getting the following message: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/manique/domains/thegangsterindustry.com/public_html/includes/topleft.php on line 206 Line 206: $total=mysql_num_rows(mysql_query("SELECT * FROM inbox WHERE username='$username' AND read='0'")); I've tried everything I can think of... It works when the "read='0'" part ain't there, but that's obviously not what I want. Read DOES exist in the DB and so do both the values (0 & 1). Anyone help? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted February 2, 2008 Share Posted February 2, 2008 Your code is written in such as way that it has no error checking and error reporting to get php/mysql to tell you why it is not working and there is no way anyone in a forum can tell you either based on the information provided. Change your code to the following - $query = "SELECT * FROM inbox WHERE username='$username' AND read='0'"; $result = mysql_query($query) or die("Query failed - Query string is: ($query), Mysql error is: " . mysql_error()); $total=mysql_num_rows($result); While you can write code the way you were, with three nested function calls, it is impossible to do any error checking, error reporting, and error recovery. Do you really want to have code that does not tell you why it is not working, and you need to wait around in a programming forum somewhere to find out what the problem might be every time it fails? BTW: I checked the mysql manual and the word read is a reserved keyword. You need to change your column name to something else. Quote Link to comment Share on other sites More sharing options...
ST-Mike Posted February 16, 2008 Share Posted February 16, 2008 Alternatively just wrap the word read with ` and `. Making line 206 the following: $total=mysql_num_rows(mysql_query("SELECT * FROM inbox WHERE username='$username' AND `read`='0'")); Though you also need to remember about monitoring and logging errors, as PFMaBiSmAd brought up. 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.