-
Notifications
You must be signed in to change notification settings - Fork 1
/
tabel_buku.php
101 lines (87 loc) · 2.77 KB
/
tabel_buku.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<!DOCTYPE html>
<html lang="en">
<head>
<title>Perpustakaan</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="assets/js/jquery.min.js"></script>
<script src="assets/js/bootstrap.min.js"></script>
</head>
<body>
<?php
if (isset($_POST['search'])) {
// here you would normally include some database connection
include('db_login.php');
$con = mysqli_connect($db_host, $db_username, $db_password,$db_database);
if (mysqli_connect_errno()){
die ("Could not connect to the database: <br />". mysqli_connect_error( ));
}
// never trust what user wrote! We must ALWAYS sanitize user input
$search_box = mysqli_real_escape_string($con, $_POST['search']);
$search_box = htmlentities($search_box);
$no=1;
function test_input($data){
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
$search_box=test_input($search_box);
if($search_box == ''){
$error_key= "Kata kunci belum dimasukkan";
$valid_key= FALSE;
} else{
$valid_key= TRUE;
}
if($valid_key == FALSE){
echo "<div class=\"alert alert-danger\">
<span class=\"glyphicon glyphicon-remove\"></span>
".$error_key."
</div>";
} else{
$query = " SELECT buku.idbuku, buku.judul, buku.pengarang, fakultas.nama, buku.stock
FROM buku, fakultas
WHERE (buku.judul LIKE '%".$search_box."%'
OR buku.pengarang LIKE '%".$search_box."%'
OR fakultas.nama LIKE '%".$search_box."%')
AND buku.idfakultas = fakultas.idfakultas ";
$result = mysqli_query($con,$query);
if (!$result){
die ("Could not query the database: <br />". mysqli_error($con));
}
$book=mysqli_num_rows($result);
if($book == null){
echo "<div class=\"alert alert-danger\">
<span class=\"glyphicon glyphicon-remove\"></span>
Buku Tidak Tersedia
</div>";
}else {
// build your search query to the database
echo "<table class=\"table table-striped\">";
echo "<tr align=\"center\">
<td>No</td>
<td>ID Buku</td>
<td>Judul</td>
<td>Pengarang</td>
<td>Fakultas</td>
<td>Stok</td>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr align=\"center\">";
echo "<td>".$no."</td>";
echo "<td align=\"left\">".$row['idbuku']."</td>";
echo "<td align=\"left\">".$row['judul']."</td>";
echo "<td align=\"left\">".$row['pengarang']."</td>";
echo "<td>".$row['nama']."</td>";
echo "<td>".$row['stock']."</td>";
echo "</tr>";
$no++;
}
echo "</table>";
}
mysqli_close($con);
}
}
?>
</body>
</html>