-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
63 lines (48 loc) · 1.47 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
<?php
include 'header.php';
$user = new User();
$books = new Books();
$user->authenticate();
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
<title>autoLib - Search for a Book</title>
</head>
<body>
<?php
/* Use PHP and the basename method.
By using this and the __FILE__ arguement we can figure out which page is being visited, so the menu.php file can figure out which pages are to be displayed as active. */
$pageName = basename(__FILE__);
include 'menu.php';
?>
<div style="margin-left:25%;padding:1px 16px;height:100%;">
<h2><div class="right"><a href="logout.php">Logout</a></div>Search for a Book</h2>
<hr/>
<h3>Search by Category</h3>
<form name="searchCategory" method="POST" action="">
<p>Category:</p>
<select name="categoryName">
<?php
$books->categoryOptions();
?></select><br/><br/>
<input type="text" name="searchQuery" required="required" placeholder="Query within category">
<br/>
<br/>
<input type="submit" value="Search">
</form>
<?php
//If either way of searching has been selected
if(isset($_POST["searchQuery"]) && !empty($_POST["searchQuery"])) {
//If searching by category
if(isset($_POST["categoryName"]) && !empty($_POST["categoryName"])) {
echo '<p>Results for search "'. $_POST["searchQuery"].'" in category '.$_POST["categoryName"];
$books->searchByCategory($_POST["categoryName"], $_POST["searchQuery"]);
}
}
?>
</div>
<?php include 'footer.php'; ?>
</body>
</html>