Hello, I have received the following error message on my website: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ptremail/public_html/admin/newmail.php on line 431 listed below is an excerpt from that file it is lines 429 to line 439: <? $sql=mysql_query("SELECT * FROM reads ORDER BY fnum"); $rows=mysql_num_rows($sql); for($i=0;$i<$rows;$i++) { mysql_data_seek($sql,$i); $arr=mysql_fetch_array($sql); extract($arr); $sq=mysql_query("SELECT * FROM signtask WHERE tasknum=$fnum"); $signups=mysql_num_rows($sq); echo" PHP: Any help would be most appreciated. Thanks!
Hi, the error tells you your SQL query is somehow wrong - "SELECT * FROM reads ORDER BY fnum" - so first of all do you have table 'reads' and column 'fnum'??
Yes, I checked for that and I do have a table 'reads' and a column 'fnum'. I also checked the database connectivity and it is working.
OK, When I did that I got the following: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ptremail/public_html/admin/newmail.php on line 431 Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in /home/ptremail/public_html/admin/newmail.php on line 435 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ptremail/public_html/admin/newmail.php on line 436 Warning: extract() [function.extract]: First argument should be an array in /home/ptremail/public_html/admin/newmail.php on line 437 Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/ptremail/public_html/admin/newmail.php on line 439
You didn't get what I want to say. Use mysql_error() in this manner $sql=mysql_query("SELECT * FROM reads ORDER BY fnum") or die(mysql_error()); Code (markup):
i don't have mysql or php environment immediately with me. but as the ocde looks so simple, i would like to look at two things. 1. Is there data in the table? 2. remove the order by clause and try.
Ok, when I did that I got the following: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'reads ORDER BY fnum' at line 1
1. Is there data in the table? Yes, there is data in the table 2. remove the order by clause and try. Did this and I still get the same error.
?php $con = mysql_connect("localhost", "peter", "abc123"); if (!$con) { die('Could not connect: ' . mysql_error()); }$db_selected = mysql_select_db("test_db",$con);$sql = "SELECT * FROM reads"; $result = mysql_query($sql,$con); echo mysql_num_rows($result);mysql_close($con); ?>
i may be wrong, but i see mysql_query call needs 2 parameters. in your code the second parameter is missing
reads is a reserved word. You need to use backticks around reads e.g. $sql=mysql_query("SELECT * FROM `reads` ORDER BY fnum") or die(mysql_error()); Code (markup):