I get this message quite often and it has popped up again here, any ideas as to why?

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\.... on line 76

line 76 is this line in bold.

$productlist = "";
$sql = mysql_query("SELECT * FROM products ORDER BY dateadded DESC");
[B]$productCount = mysql_num_rows($sql); // count the output amount[/B]
if ($productCount > 0) {
	while($row = mysql_fetch_array($sql)){ 
             $id = $row["id"];
			 $productname = $row["productname"];
			 $price = $row["price"];
			 $dateadded = strftime("%b %d, %Y", strtotime($row["dateadded"]));
			 $productlist .= "Product ID: $id - <strong>$productname</strong> - $price - <em>Added $dateadded</em> &nbsp; &nbsp; &nbsp; <a href='inventoryedit.php?pid=$id'>edit</a> &bull; <a href='inventorylist.php?deleteid=$id'>delete</a><br />";
} else {
	$productlist = "You have no products listed in your store yet";

If anyone has the answer for this that will be great.

5 Years
Discussion Span
Last Post by nandkishor.sharma.372_1

For as far as I know, executing a COUNT instead of count_num_rows is faster, performance wise.

Your new query would look like

SELECT COUNT(a_unique_field_occuring_in_every_record_that_is_selected) AS num_rows, * FROM products ORDER BY dateadded DESC

I'm not 100% sure if it is faster though, but with this query, you could use mysql_fetch_assoc to fetch your results. $fetch will then be the number of rows.


May be you have mistaken in table name or fieldname. so just echo your query as given below. Copy that query and paste it in phpmyadmin's SQL Section and see the output.

echo $query="SELECT * FROM products ORDER BY dateadded DESC";
$sql = mysql_query($query);
$productCount = mysql_num_rows($sql); // count the output amount

Thanks for your help guys, i solved this yesterday. I checked the entire code and realized that i had forgotten to insert the connect to the mysql database code, it was not actually the code itself!


i get this message:
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in D:\xamps\xampp\htdocs\register.php on line 19



$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$repassword = $_POST['password2'];
$phoneno = $_POST['phoneno'];
$address = $_POST['address'];
$postcode = $_POST['postcode'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];

$sql = "select * from user where username='".$username."'";
$result = mysql_query($sql) ;
$row = mysql_num_rows($result);  line 19
if($row!= 0)
    echo "Register failed. Your username has been used by other member!<br />";
    echo "<a href=\"regframe.php\">Try again</a>";

$sql2 = "insert into user('username','email','password','retypepassword','phoneno','address','postcode','city','state','country') values ( '".$username."', '".$email."','".$password."','".$repassword."','".$phoneno."', '".$address."','".$postcode."','".$city."','".$state."','".$country."','user')";
mysql_query($sql2) or die ("Register fail! Please try again later!");

echo "Thank you for sign up as member<br/>";
echo "Please Login to continue";
echo "<meta http-equiv=\"refresh\"content=\"1;URL=loginpage1.php\">";

Please help!! thanks

Edited by Dani: Formatting fixed

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.