By Narosa Publishing House Pvt Ltd
Download Free Book "Advanced Engineering Mathematics" By Rk Jain Srk Iyengar Pdf
Mathematics
Category:Mathematics books
Category:Science books
Category:University of Delhi Press booksQ:
PHP mysql_num_rows returning zero
I want to create a database table with data pulled from a third party source and written to the database using PHP and MySQL, but the following code doesn't seem to be getting anything into the database. I don't see any errors, so I'm thinking it must be something stupid like a typo or something, but it shouldn't be that.
In the php file that creates the database, I have tried var_dump(mysql_num_rows($result)) just before this code and I'm getting back 0, so I know that it's reading the sql.
$result = mysql_query("select * from `data` where `key`='$key'") or die(mysql_error());
var_dump(mysql_num_rows($result));
$row = mysql_fetch_array($result);
echo $row['name'];
EDIT: Here is the error I'm getting when I run this page on my localhost. I can't see anything obvious as the error. Could someone help me out with this?
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/sites/templink.com/public_html/siteprotocode.php on line 23
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/sites/templink.com/public_html/siteprotocode.php on line 24
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/sites/templink.com/public_html/siteprotocode.php on line 26
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/sites/templink.com/public_html/siteprotocode.php on line 26
Name
EDIT 2: Adding the $dbc variable and the connection stuff to the question
A:
You are forgetting to close the connection.
$ ac619d1d87
Related links:
Comments