Does anyone know what's wrong with this code? I just started learning php &
mysql from a book and this code is copied directly from it, yet it still
fails to work... I always get the following error:
Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result
resource in /home/tjc/public_html/results.php on line 40
<?php
// create short varibles names
$searchtype = $HTTP_POST_VARS['searchtype'] ;
$searchterm = $HTTP_POST_VARS['searchterm'] ;
$searchterm = trim($searchter m) ;
if (!$searchtype || !$searchterm)
{
echo "No search details entered" ;
exit ;
}
$searchtype = addslashes($sea rchtype) ;
$searchterm = addslashes($sea rchterm) ;
@ $db = mysql_pconnect( 'localhost', 'tjc_bookorama' , 'bookorama123') ;
if (!$db)
{
echo "Error: Could not connect to db" ;
exit ;
}
mysql_select_db ("tjc_books" );
$query = "SELECT * FROM books WHERE ".$searchty pe." LIKE
'%".$searchterm ."%'" ;
$result = mysql_query($qu ery) ;
$num_results = mysql_num_rows( $result); // line 40
echo "<p>Number of books found: ".$num_results. "</p>" ;
for ($i = 0; $i <num_results; $i++)
{ {
$row = mysql_fetch_arr ay($result) ;
echo '<p><strong>'.( $i + 1).'. Title: ' ;
echo htmlspecialchar s(stripslashes( $row['title'])) ;
echo '</strong><br />Author: ' ;
echo stripslashes($r ow['author']) ;
echo '<br />ISBN: ' ;
echo stripslashes($r ow['isbn']) ;
echo '<br />Price: ' ;
echo stripslashes($r ow['price']) ;
echo '</p>' ;
}
?>
*************** *************** *************** *************** *************** *
*****
QOTSA: "Nicotine, Valium, Vicodin, Marijuana, Ecstacy and Alcohol"
Einstein: "Imaginatio n is More Important Than Knowledge"