Jump to content

Help! This is driving me crazy!


Maniacility

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.