-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
82 lines (68 loc) · 2.45 KB
/
search.php
File metadata and controls
82 lines (68 loc) · 2.45 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
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
<?php require './includes/_dbconnect.php'; ?>
<?php $title = "Search Result";?>
<?php require './includes/_header.php'; ?>
<div class="recipeGrid">
<?php
if (isset($_POST['search-submit'])) {
$search = $_POST['query'];
$search = strtolower($search);
// changes input to lowercase
$search = htmlspecialchars($search);
// changes characters
$search = mysqli_real_escape_string($connection, $search);
// no SQL injection
$query = "SELECT * FROM `recipes`
WHERE `title` LIKE '%$search%'
OR `side` LIKE '%$search%'
OR `ingredients` LIKE '%$search%'
ORDER BY `id` ASC";
$result = mysqli_query($connection, $query);
$queryResult = mysqli_num_rows($result);
// If there are any Results
if ($queryResult > 0) {
while ($row = mysqli_fetch_assoc($result)) {
?>
<div class="individualRecipe">
<a href="result.php?id=<?php echo $row['id']; ?>" class="recipeHyperlink">
<img src="./media/recipeImages/<?php echo $row['images']; ?>/main_pic.jpg" alt="<?php echo $row['title']; ?>" id="main"></a>
<h2 class="gridTitle"><?php echo $row['title']; ?></h2>
<p class="gridSide">with <?php echo $row['side']; ?></p>
</div>
<?php
}
}
else {
echo "<div class=\"errorResult\">";
echo "<img class=\"resultErrorImage\" src=\"./media/assets/kitchenDisaster2.gif\" alt=\"Error Image\">";
echo "<h1 class=\"resultTitle\">Sorry!</h1>";
echo "<h3 class=\"resultSide\">We can't find that page.</h3>";
echo "<br>";
echo "<a href=\"index.php\" class=\"errorLink\">";
echo "<h4 class=\"errorButton\">Home</h4>";
echo "</a>";
echo "</div>";
}
}
// Release Returned Data
mysqli_free_result($result);
// Close Database Connection
mysqli_close($connection);
?>
</div>
<!-- Trigger/Open Modal -->
<button id="myBtn" onclick="helpMe();" title="Help">Help</button>
<!-- Modal -->
<div id="myModal" class="modal">
<!-- Modal content -->
<div class="modalContent">
<div class="modalHeader">
<span class="close">×</span>
<h2 class="modalTitle">Instructions</h2>
</div>
<div class="modalBody">
<p>Select a recipe from the list above. You can also use the search bar to find what you are looking for, or find a recipe by using the filters above.</p>
</div>
</div>
</div>
<script src="javascript.js"></script>
<?php require './includes/_footer.php'; ?>