Results 1 to 4 of 4

Thread: mySQL error - argument is not a valid MySQL result resource

  1. #1
    Awesomexr's Avatar
    Awesomexr is offline x10 Sophmore
    Join Date
    Dec 2008
    Location
    haslam.pcriot.com
    Posts
    118

    mySQL error - argument is not a valid MySQL result resource

    Code:
    Warning:  mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/haslamx/public_html/vote/src/index.php on line 115
    Here is line 115 of index.php:

    Code:
    <?php
    /**
    Display the results from the database
    **/
    $q = "SELECT * FROM entries";
    $r = mysql_query($q);
    
    >> Line 115 :if(mysql_num_rows($r)>0): //table is non-empty
        while($row = mysql_fetch_assoc($r)):
            $net_vote = $row['votes_up'] - $row['votes_down']; //this is the net result of voting up and voting down
    ?>
    Can anyone tell me what I'm doing wrong? Help would be greatly appreciated, thank you!

  2. #2
    marshian's Avatar
    marshian is offline x10 Elder
    Join Date
    Jan 2008
    Location
    Belgium
    Posts
    526

    Re: mySQL error - argument is not a valid MySQL result resource

    This error usually means the query failed. Try adding this to the script (after $r = mysql_query($q))
    Code:
    echo mysql_error();
    This will tell you what's wrong about the query, which is probably the problem.

  3. #3
    Awesomexr's Avatar
    Awesomexr is offline x10 Sophmore
    Join Date
    Dec 2008
    Location
    haslam.pcriot.com
    Posts
    118

    Re: mySQL error - argument is not a valid MySQL result resource

    Quote Originally Posted by marshian View Post
    This error usually means the query failed. Try adding this to the script (after $r = mysql_query($q))
    Code:
    echo mysql_error();
    This will tell you what's wrong about the query, which is probably the problem.
    Thank you, i've found out the problem and i'l fix it now.

  4. #4
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: mySQL error - argument is not a valid MySQL result resource

    Make sure your scripts handle errors properly. This means catching exceptions and testing return values (and throwing exceptions and returning error values, when appropriate, as the point an error is detected is often not the point it can be handled), and giving useful information in error messages without revealing sensitive information. Implement error handling early; it will help you in your development by letting you know what's failing and where.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Jon Skeet's and Eric Raymond's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

Similar Threads

  1. [PHP] MySQL and PHP
    By Bryon in forum Tutorials
    Replies: 45
    Last Post: 02-09-2013, 09:45 PM
  2. MySQL Issues Here
    By Corey in forum Service Alerts
    Replies: 304
    Last Post: 01-06-2008, 09:10 PM
  3. MySQL / Absolut / Not a valid MySQL result resource
    By altrock182182 in forum Free Hosting
    Replies: 0
    Last Post: 12-21-2007, 01:15 PM
  4. Warning: mysql_fetch_assoc():
    By chatflash in forum Free Hosting
    Replies: 9
    Last Post: 11-27-2007, 05:29 PM
  5. Have a problem with my forum
    By tikloos in forum Scripts, 3rd Party Apps, and Programming
    Replies: 43
    Last Post: 01-19-2006, 01:14 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
dedicated servers