No output with PHP code when accessing database

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 Results

Book-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]

Does it produce that error message when you run a search for nothing? Do you actually have data in your database for it to look through? If the database is not populated then that may explain the results you are gettting.

The database has information in it. I found out basically that the @ symbol the book had me using was suppressing an error. The class mysqli couldn’t be found so that was the problem. I tried many different methods to fix this problem but basically I ended up just uninstalling what I had done and installing xampp. Everything seems to be working fine now. I suppose I need to mark it as solved.

Sponsor our Newsletter | Privacy Policy | Terms of Service