-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsearch.php
More file actions
40 lines (35 loc) · 1.23 KB
/
Copy pathsearch.php
File metadata and controls
40 lines (35 loc) · 1.23 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
<?php
$host = "localhost";
$dbUsername = "root";
$dbPassword = "";
$dbname = "accounts";
if(!$conn = new mysqli($host, $dbUsername, $dbPassword, $dbname)){
die("Failed to connect");
}
?>
<h1>Search Page</h1>
<div class = "article-container">
<?php
if(isset($_POST['submit-search'])){
$search = mysqli_real_escape_string($conn, $_POST['search']);
$sql = "SELECT * FROM listings WHERE TextbookTitle LIKE '%$search%' OR
Description LIKE '%$search%' OR ISBN LIKE '%$search%' OR BookCondition LIKE '%$search%' OR Price LIKE '%$search%'";
$result = mysqli_query($conn, $sql);
$queryResult = mysqli_num_rows($result);
echo "There are ".$queryResult." results!";
if($queryResult > 0){
while($row = mysqli_fetch_assoc($result)){
echo "<div class = 'article-box'>
<h3>".$row['TextbookTitle']."</h3>
<p>".$row['ISBN']."</p>
<p>".$row['Price']."</p>
<p>".$row['BookCondition']."</p>
<p>".$row['Description']."</p>
</div>";
}
}else{
echo "There are no results matching your search!";
}
}
?>
</div>