-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
85 lines (75 loc) · 2.94 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Search Result | Readers' Mind</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,[email protected],100..700,0..1,-50..200" />
<link rel="stylesheet" href="search-style.css">
<link rel="icon" href="logo.png">
<?php
#check the connection
$connection = mysqli_connect('localhost', 'root', '', 'bookself');
if(mysqli_connect_errno()){
die('Database connection failed' . mysqli_connect_error());
} else {
echo 'Database connected successfully !';
}
$search='';
?>
</head>
<body>
<!--search form-->
<div class="frm02">
<h2>Search about Books</h2>
<form action="search.php" method="get" class="scnd-fm">
<input type="text" name="query" id="srchbr" placeholder="Type the key word ..." <?php echo $search?>>
<button type="submit" value="search" id="search" name="search"><span class="material-symbols-outlined">
search
</span></button>
</form>
</div>
<div class="main">
<table>
<tr>
<th>Book Name</th>
<th>Author</th>
<th>Category</th>
<th>Description</th>
<th>Sender's E-mail</th>
</tr>
<?php
$row = '';
$sql = "SELECT * FROM bookself ORDER BY name";
$result = $connection->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["name"]. "</td><td>" . $row["author"] . "</td><td>"
. $row["genre"]. "</td><td>" .$row["sammury"]. "</td><td>" .$row["sendemail"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}
#search query
if( isset ($_GET['search'])){
$search = mysqli_real_escape_string($connection, $_GET['search']);
$result = "SELECT * FROM bookself WHERE name LIKE %{$search}% OR author LIKE %{$search}% OR genre LIKE %{$search}% OR sammury LIKE %{$search}% OR sendemail LIKE %{$search}% AND is_deleted=0 ORDER BY name";
} else {
$result = "SELECT * FROM bookself ORDER BY name";
}
?>
</table>
</div>
<!--bottum-->
<div class="botm">
<p class="qt">A Room without Book is like Body without Soul..</p>
<div class="btmtbl">
<p>Yara'</p>
<p>@2022</p>
</div>
</div>
</body>
</html>
<?php mysqli_close($connection) ?>