Hello experts,

I'm having some difficults with the code that i have used from one of the PHP, MySQL books. As the error that appears is in bold on line 17, and the error that shows is listed below:

"Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\wamp\www\Testing PHP with MySQL uses online Tutorials\Testing_with_MySQL_Database.php on line 17"

<html>
<body>

<?php
//Open connection to MySQL server
$connection = mysql_connect('localhost','root') or die ('Unable to connect!');

// select database for use
mysql_select_db('movies') or die ('Unable to select database!');

// create and execute query
$query = 'SELECT * FROM movies';
$result = mysql_query($query)
or die ('Error in query: $query. ' . mysql_error());

// check if records were returned
if (mysql_num_rows(Sresult) > 0)
{
	//Print HTML table
	echo '<table width = 100% cellpadding=10 cellspacing=0 border=1>';
	echo
		 '<tr><td><b>Customer ID/b</td><tr><td><b>Customer Full Name/b</td><tr><td><b>Date Of Birth/b</td>';

	// iterate over record set
	// print each field
	while($row = mysql_fetch_row($result))
	{
		echo '<tr>';
		echo '<td>' . $row[0] . '</td>';
		echo '<td>' . $row[1] . '</td>';
		echo '<td>' . $row[2] . '</td>';
		echo '</tr>';
	}
	echo '</table>';
}
else
{
	// print error message
	echo 'No rows found!';
}

// once processing is complete
// free result set
mysql_free_result($result);

//close connection to MySQL server
mysql_close($connection);
?>

</body>
</html>

Please help,

Thanks,
Mitesh

Hello,
it says Sresult, instead of $result. It's just not a MySQL result, not a PHP variable.

Shaffer.

Hello,

What a stupid mistake i made, i was sitting here for a good 20mins and i was confused!

Thanks alot for you help,
Mitesh

if (mysql_num_rows(Sresult) > 0)

Should be

if (mysql_num_rows($result) > 0)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.