Skip to content
PHP Logo

How can the "mysql_num_rows() expects parameter 1 to be resource, boolean given" error be resolved in PHP?

The error "mysql_num_rows() expects parameter 1 to be resource, boolean given" occurs when the query execution fails and returns a boolean value (false) instead of a resource. To resolve this issue, you should check if the query execution was successful before calling mysql_num_rows().

php
// Check if the query execution was successful
$result = mysql_query($query);
if($result === false) {
    die("Error in query execution: " . mysql_error());
}

// Now you can safely use mysql_num_rows()
$num_rows = mysql_num_rows($result);