Hello!
I am making a search engine in my website. The code is taken from the book PHP and MYSQL Web Developing written by Luke Welling and Laura Thompson.
It's a very useful book.
The problem is that I don't know how to display the image that I have uploaded in my mysql table. The results.php file displays the image like a bunch of numbers and symbols...
I have uploaded the image in the mysql database and store it as longblob type.
Here is the code I use:
search.html:
results.php:
Can anyone help me to make the image display normally? Thanks very much.
I am making a search engine in my website. The code is taken from the book PHP and MYSQL Web Developing written by Luke Welling and Laura Thompson.
It's a very useful book.
The problem is that I don't know how to display the image that I have uploaded in my mysql table. The results.php file displays the image like a bunch of numbers and symbols...
I have uploaded the image in the mysql database and store it as longblob type.
Here is the code I use:
search.html:
HTML:
<html>
<head>
<title>Book-O-Rama Catalog Search</title>
</head>
<body>
<h1>Book-O-Rama Catalog Search</h1>
<form action="results.php" method="post">
Choose Search Type:<br />
<select name="searchtype">
<option value="author">Author
<option value="title">Title
<option value="isbn">ISBN
<option value="price">Price
<option value="image">Image
</select>
<br />
Enter Search Term:<br />
<input name="searchterm" type="text" size="40">
<br />
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>
results.php:
Code:
<html>
<head>
<title>Book-O-Rama Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?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', 'username', 'password', 'database');
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 "<p>Number of books found: ".$num_results."</p>";
for ($i=0; $i <$num_results; $i++) {
$row = $result->fetch_assoc();
echo "<p><strong>".($i+1).". Title: ";
echo htmlspecialchars(stripslashes($row['title']));
echo "</strong><br />Author: ";
echo stripslashes($row['author']);
echo "<br />ISBN: ";
echo stripslashes($row['isbn']);
echo "<br />Price: ";
echo stripslashes($row['price']);
echo "<br />Image: ";
echo stripslashes($row['image']);
echo "</p>";
}
$result->free();
$db->close();
?>
</body>
</html>
Can anyone help me to make the image display normally? Thanks very much.