I’m currently working my way through a PHP and MYSQL book. I’ve successfully created databases and have had no issues with PHP so far but the example the book is giving isn’t producing any output when I search. I was hoping that someone could help me figure out why. I’m not getting an error message or anything. It’s just blank.
[php]
Book-O-Rama Search ResultsBook-O-Rama Search Results
<?php // create short variable names $searchtype=$_POST['searchtype']; $searchterm=trim($_POST['searchterm']);if (!$searchtype || !$searchterm) {
echo ‘You have not entered search details. Please go back and try again.’;
exit;
}
if (!get_magic_quotes_gpc()){
$searchtype = addslashes($searchtype);
$searchterm = addslashes($searchterm);
}
@ $db = new mysqli(‘localhost’, ‘bookorama’, ‘bookorama123’, ‘books’);
if (mysqli_connect_errno()) {
echo ‘Error: Could not connect to database. Please try again later.’;
exit;
}
$query = “select * from books where “.$searchtype.” like '%”.$searchterm."%’";
$result = $db->query($query);
$num_results = $result->num_rows;
echo “
Number of books found: “.$num_results.”
”;for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo “
”.($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row[‘title’]));
echo "
Author: ";
echo stripslashes($row[‘author’]);
echo "
ISBN: ";
echo stripslashes($row[‘isbn’]);
echo "
Price: ";
echo stripslashes($row[‘price’]);
echo “
}
$result->free();
$db->close();
?>
[/php]