-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpeminjaman_cekStatus.php
120 lines (102 loc) · 3.51 KB
/
peminjaman_cekStatus.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<!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_nim= "Anda Belum Memasukkan NIM";
$valid_nim= FALSE;
} elseif(!preg_match("/^[0-9]/", $search_box)){
$error_nim= "Format NIM Salah";
$valid_nim= FALSE;
} else{
$valid_nim= TRUE;
}
if($valid_nim == FALSE){
echo "<div class=\"alert alert-danger\">
<span class=\"glyphicon glyphicon-remove\"></span>
".$error_nim."
</div>";
} else {
$q = "select nim from mahasiswa where nim='".$search_box."'";
$r = mysqli_query($con,$q);
if (!$r){
die ("Could not query the database: <br />". mysqli_error($con));
}
$mhs=mysqli_num_rows($r);
if($mhs == 0){
echo "<div class=\"alert alert-danger\">
<span class=\"glyphicon glyphicon-remove\"></span>
Mahasiswa Tidak Terdaftar
</div>";
} else {
// build your search query to the database
$query="SELECT peminjaman.nim, peminjaman.idpinjam, detail_pinjam.idbuku, buku.judul
FROM detail_pinjam , peminjaman, buku
WHERE peminjaman.nim = '".$search_box."'
AND peminjaman.status_peminjaman = 'Y'
AND detail_pinjam.idpinjam = peminjaman.idpinjam
AND detail_pinjam.idbuku=buku.idbuku";
/* $query="SELECT peminjaman.nim, peminjaman.idpinjam,peminjaman.tgl_pinjam,peminjaman.tgl_kembali, detail_pinjam.idbuku, detail_pinjam.denda
FROM detail_pinjam
RIGHT JOIN peminjaman ON detail_pinjam.idpinjam = peminjaman.idpinjam
WHERE peminjaman.nim = '".$search_box."'
AND peminjaman.status_peminjaman = 'Y'
"; */
$result = mysqli_query($con,$query);
if (!$result){
die ("Could not query the database: <br />". mysqli_error($con));
}
$jml_buku=mysqli_num_rows($result);
echo "<div class=\"alert alert-success\">
<span class=\"glyphicon glyphicon-ok\"></span>
Sedang Pinjam <i>".$jml_buku."</i> Buku
</div>";
if(($jml_buku==1) ||($jml_buku==2)){
echo "<table class=\"table table-striped\">";
echo "<tr align=\"center\">
<td>NO</td>
<td>ID Buku</td>
<td>Judul Buku</td>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr align=\"center\">";
echo "<td>".$no."</td>";
echo "<td>".$row['idbuku']."</td>";
echo "<td align=\"left\">".$row['judul']."</td>";
$no++;
echo "</tr>";
}
echo "</table>";
}
}
}
}
mysqli_close($con);
?>
</body>
</html>