Specifications

@ $db = mysql_pconnect(“localhost”, “bookorama”, “bookorama”);
if (!$db)
{
echo “Error: Could not connect to database. Please try again later.”;
exit;
}
mysql_select_db(“books”);
$query = “select * from books where “.$searchtype.” like
‘%”.$searchterm.”%’”;
$result = mysql_query($query);
$num_results = mysql_num_rows($result);
echo “<p>Number of books found: “.$num_results.”</p>”;
for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_array($result);
echo “<p><strong>”.($i+1).”. Title: “;
echo htmlspecialchars( stripslashes($row[“title”]));
echo “</strong><br>Author: “;
echo htmlspecialchars (stripslashes($row[“author”]));
echo “<br>ISBN: “;
echo htmlspecialchars (stripslashes($row[“isbn”]));
echo “<br>Price: “;
echo htmlspecialchars (stripslashes($row[“price”]));
echo “</p>”;
}
?>
</body>
</html>
Figure 10.2 illustrates the results of using this script to perform a search.
Accessing Your MySQL Database from the Web with PHP
C
HAPTER 10
10
ACCESSING
YOUR MYSQL
DATABASE
231
LISTING 10.2 Continued
13 7842 CH10 3/6/01 3:36 PM Page 231