How can the error message "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" be resolved in PHP 5 when querying a database?

The error message "Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource" occurs when the query doesn't return a valid result set. To resolve this issue, you need to check if the query was successful before calling mysql_num_rows() function. This can be done by checking the return value of mysql_query() function to ensure it's a valid result resource.

// Perform the query
$result = mysql_query($query);

// Check if the query was successful
if($result){
    // Use mysql_num_rows() function to get the number of rows
    $num_rows = mysql_num_rows($result);
    echo "Number of rows: $num_rows";
} else {
    echo "Error executing query: " . mysql_error();
}