-1

I tried to search and found some similar questions but none seemed to help with my code. I upgraded to a new server:

  • MySQL = 5.0.96-community
  • PHP = 4.4.9

I get following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /path/to/file/filename.php on line 209

Here's the Line 209:

$num_rows = mysql_num_rows($result);

The code right above it for reference is:

<?

// Connect to DB

$db = mysql_connect("localhost","db_name","password");

if (!$db)
{
echo "No connection.";
exit;
}

mysql_select_db("db_name");

$v = str_replace(' ','_',$v);

$query = "SELECT * FROM reviews";
$result = mysql_query($query);

$num_rows = mysql_num_rows($result);
aksu
  • 5,221
  • 5
  • 24
  • 39

1 Answers1

0

You aren't doing basic error checking:

$result = mysql_query($query);

For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error

See also mysql_error():

Returns the text of the error message from previous MySQL operation

Álvaro González
  • 142,137
  • 41
  • 261
  • 360