-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresults.php
More file actions
48 lines (45 loc) · 1.26 KB
/
results.php
File metadata and controls
48 lines (45 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Book-O-Rama Catalog Search Results</title>
</head>
<body>
<h1>Book-O-Rama Search Results</h1>
<?php
$searchtype = $_POST['searchtype'];
$searchterm = $_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','root','','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 "<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 "</p>";
};
$result->free();
$db->close();
?>
</body>
</html>