-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtabel_buku1.php
101 lines (92 loc) · 3.05 KB
/
tabel_buku1.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['judul']) || ($_POST['pengarang']) || ($_POST['fakultas'])) {
// 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
$judul = mysqli_real_escape_string($con, $_POST['judul']);
$pengarang = mysqli_real_escape_string($con, $_POST['pengarang']);
$fakultas = mysqli_real_escape_string($con, $_POST['fakultas']);
$judul = htmlentities($judul);
$pengarang = htmlentities($pengarang);
$fakultas = htmlentities($fakultas);
$no=1;
function test_input($data){
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
$judul=test_input($judul);
$pengarang=test_input($pengarang);
$fakultas=test_input($fakultas);
if(($judul == '') && ($pengarang == '') && ($fakultas == '')){
$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 '%".$judul."%'
AND buku.pengarang LIKE '%".$pengarang."%'
AND buku.idfakultas LIKE '%".$fakultas."%'
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 {
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>