-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
86 lines (76 loc) · 2.05 KB
/
search.php
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to DIT Library Management System</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
require_once "db.php";
include "header.html";
//if-statements to check if a search field is empty.
if(!empty($_POST["bookTitle"]))
{
$bookTitle = mysqli_real_escape_string($con, $_POST["bookTitle"]);
}
else
{
$bookTitle = "~";
echo $bookTitle;
}
if(!empty($_POST["bookAuthor"]))
{
$bookAuthor = mysqli_real_escape_string($con, $_POST["bookAuthor"]);
}
else
{
$bookAuthor = "~";
echo $bookAuthor;
}
if(!empty($_POST["category"]))
{
$category = mysqli_real_escape_string($con, $_POST["category"]);
}
else
{
$category= "~";
}
echo "Didn't find what you were looking for? <a href='userhome.php'>New Search</a>";
//category using SQL Natural Join to return category name in search results instead of category number
$query = "Select * From books NATURAL JOIN categories where categories.CategoryDesc LIKE '%" .$category ."%' OR books.BookTitle LIKE '%" .$bookTitle ."%' OR books.Author LIKE '%" .$bookAuthor."%'";
$result=mysqli_query($con, $query) or die(mysqli_error());
echo '<table border="1" width="95%" align="center">'."\n";
echo "<tr><th>ISBN</th><th>Title</th><th>Author</th><th>Edition</th><th>Year</th><th>Category</th><th>Reserved</th><th>Reserve?</th><tr>";
while($row = mysqli_fetch_array($result, MYSQLI_BOTH)){
echo "<tr><td>";
echo(htmlentities($row[1]));
echo("</td><td>");
echo(htmlentities($row[2]));
echo("</td><td>");
echo(htmlentities($row[3]));
echo("</td><td>\n");
echo(htmlentities($row[4]));
echo("</td><td>\n");
echo(htmlentities($row[5]));
echo("</td><td>\n");
echo(htmlentities($row[7]));
echo("</td><td>\n");
echo(htmlentities($row[6]));
If($row[6]!= 'Y')
{
echo("</td><td>\n");
echo('<a href="reserve.php?id='.htmlentities($row[1]).'">Reserve</a>');
}
else
{
echo("</td><td>\n");
echo("Not Available");
}
echo("</td></tr>\n");
}
echo "</br>";
echo "</br>";
mysqli_close($con);
?>
</body>
</html>