mySQL error - argument is not a valid MySQL result resource

Awesomexr

New Member
Messages
118
Reaction score
4
Points
0
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! :)
 

marshian

New Member
Messages
526
Reaction score
9
Points
0
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.
 

Awesomexr

New Member
Messages
118
Reaction score
4
Points
0
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. :)
 

misson

Community Paragon
Community Support
Messages
2,572
Reaction score
72
Points
48
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.
 
Top