webdesignmad Posted August 3, 2011 Share Posted August 3, 2011 I'm making a php mailing list where users submit their name and email. It adds that to a database. But when i try to open viewSubscribers.php (the file displaying users), it says "Warning: mysql_num_rows() expects parameter 1 to be resource, string given in M:\Programs\xampp\htdocs\HTML\ViewSubscribers.php on line 22". Here's the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta content="text/html; charset=utf-8" http-equiv="Content-Type" /> <title>ViewSubscribers.php</title> </head> <body> <table> <tr> <th align="left">Name</th> <th align="left">Email</th> </tr> </table> <table> <?php $link = mysql_connect("localhost", "my_username", "my_password") or die ('I cannot connect to the DB'); mysql_select_db ("mailinglist",$link) or die ("Unable to select DB."); $query="SELECT * FROM mailinglist"; $result=mysql_query($query, $link); $num=mysql_num_rows("$result"); mysql_close(); $i=0; while ($i < num){ $name=mysql_result($result,$i,"name"); $email=mysql_result($result,$i,"email"); ?> <tr> <td> <?php print $name ?> </td> <td> <?php print $email ?> </td> </tr> <?php $i++; } ?> </table> </body> </html> Quote Link to comment Share on other sites More sharing options...
gristoi Posted August 3, 2011 Share Posted August 3, 2011 mysql_close(); your closing the resource off before calling it. move this to the end of your mysql Quote Link to comment Share on other sites More sharing options...
the182guy Posted August 3, 2011 Share Posted August 3, 2011 Don't wrap variables in quotes like this $num=mysql_num_rows("$result"); It should be $num=mysql_num_rows($result); Quote Link to comment Share on other sites More sharing options...
webdesignmad Posted August 3, 2011 Author Share Posted August 3, 2011 Thanks guys, that seems to do it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.