Jump to content

mysql_num_rows(): supplied argument is not a valid MySQL result


Recommended Posts

Hi,

I check my error-logs on my website (www.gpstudios.com) and theres always lines and lines of this sort of stuff:

 

[11-May-2010 06:43:21] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/news_comments.php on line 18

[11-May-2010 06:56:28] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13

[11-May-2010 06:56:29] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13

[11-May-2010 08:01:36] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123

[11-May-2010 08:01:36] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/specific_category.php on line 18

[11-May-2010 08:01:36] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123

[11-May-2010 08:01:40] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123

[11-May-2010 08:01:40] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/specific_category.php on line 18

[11-May-2010 08:01:40] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/class/functions.class.php on line 123

[11-May-2010 08:10:13] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13

[11-May-2010 08:17:44] PHP Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/hedgehog/public_html/search.php on line 13

 

As you can see they happen in clumps, and not very often at all (in terms of errors/visitors).

I'm pretty sure it's to do with my server just not connecting to the mysql database for small periods of time... In which case it's not fixable.

 

Here is the php that I use that generate these errors:

 

function get_category_name()
{
    $args = func_get_args();

    $catsql = mysql_query("select * from categories where id = $args[0]");

    if(mysql_num_rows($catsql) > 0)
    {
        $result = mysql_fetch_array($catsql, MYSQL_ASSOC);

        return $result['category_name'];
    }
}

 

This is from functions.class.php. All the other errors I get are less frequent, but anyway, they are more or less exactly that (the mysql is written identically apart from different queries obviously)

 

So, I'm guessing the answer is there's something wrong with my server, but in that case, do I just ignore these infrequent errors?

You are not validating the data being put into your query. Anytime $args[0] is empty or non-numeric, your query will fail, which will cause any code that expects $catsql to be a result resource to also fail and produce an error.

 

You need to validate $args[0] to make sure it contains something and contains a number (or cast it as a number.)

 

To troubleshoot this, you would need to find out what is actually being supplied in the function call to get_category_name, then either find and fix what is allowing the function to be called with a value that is not expected.

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.