You are on page 1of 7

Database

Nama db =” tes”
Tabel “admin”

Tabel “buku”

Login.php
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
table {
margin-top: 100px;
border-radius: 5px;
background-color: tomato;
color: white;
}
</style>
</head>
<body>
<form method="post" action="proseslogin.php">
<center>
<table>
<tr>
<td colspan="3"><center><b>LOGIN!</b></center></td>
</tr>
<tr>
<td>Username</td>
<td>:</td>
<td><input type="text" name="uname" required="required"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input type="password" name="pword" required="required"></td>
</tr>
<tr>
<td colspan="3"><center><input type="submit" name="X"></center></td>
</tr>
</table>
</center>
</form>
</body>
</html>
Proseslogin.php

<?php
include 'koneksi.php';
if (isset($_POST["X"])) {
$uname=$_POST['uname'];
$pword=$_POST['pword'];

$sql=mysqli_query($kons, "SELECT * FROM admin WHERE username='$uname' AND


password='$pword' ");

$pecah=mysqli_num_rows($sql);

if ($pecah>0) {
session_start();
$_SESSION["user"]=$uname;
echo "<script language=javascript>
window.alert('Login Berhasil');
javascript:document.location='index.php';
</script>";
}else{
echo "<script language=javascript>
window.alert('Login Gagal');
javascript:document.location='login.php';
</script>";
}
}

?>
Koneksi.php
<?php
$host="localhost";
$user="root";
$password="";
$database="tes";
$kons = mysqli_connect($host,$user,$password,$database);
?>
Logout.php
<?php

session_start();
unset($_SESSION);
session_unset();
session_destroy();
header('location:login.php');

?>
Index.php
<?php

include 'koneksi.php';
session_start();
if (empty($_SESSION["user"])) {
echo "<script language=javascript>
window.alert('Maaf Anda Belum Login');
javascript:document.location='login.php';
</script>";
}

?>

<!DOCTYPE html>
<html>
<head>
<title>Halaman Admin</title>
<style type="text/css">

body{
margin:0;
}

.container{
width: 80%;
margin-left: 10%;
margin-top: 1%;
}

.head{
background-color: red;
width: 100%;
height: 150px;
}

.kiri{
background-color: tomato;
width: 30%;
height: 460px;
float: left;
}

.kanan{
float: left;
background-color: grey;
width: 70%;
height: 460px;
}

</style>
</head>
<body>
<div class="container">
<div class="head">
<center>
<form action="cari.php" method="post" target="frameone">
<strong>Pencarian Buku:</strong>

<input type="text" name="txtCari" size="45"/>


<input type="submit" value="Search" name="submit"/>
</form>
</center>
</div>
<div class="kiri">
<a href="daftarbuku.php" target="frameone">Daftar Buku</a><br>
<a href="tambah.php" target="frameone">Tambah Buku</a><br>
<a href="logout.php">Logout</a>
</div>
<div class="kanan">
<iframe src="" name="frameone" height="100%" width="100%" frameborder="0"></iframe>
</div>
</div>
</body>
</html>
Daftarbuku.php

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<table border="1px">
<tr style="background-color: green;">
<th>ISBN</th>
<th>JUDUL BUKU</th>
<th>PENULIS</th>
<th>PENERBIT</th>
<th>TAHUN RILIS</th>
<th>MENU</th>
</tr>
<?php
include'koneksi.php';

if (isset($_GET['delete'])) {
$idx = $_GET['id'];
mysqli_query($kons, "DELETE FROM buku WHERE Isbn = '$idx'");
echo "<script> alert('Data Terhapus'); document.location='daftarbuku.php'; </script>";
}

$squl=mysqli_query($kons, "SELECT * FROM buku");


if ($squl==FALSE) {
die(mysqli_error($squl));
}
while ($tangkap=mysqli_fetch_array($squl)) {
?>
<tr>
<td><?php echo $tangkap['Isbn']; ?> </td>
<td><?php echo $tangkap['Judul_Buku']; ?> </td>
<td><?php echo $tangkap['Penulis']; ?></td>
<td><?php echo $tangkap['Penerbit']; ?></td>
<td><?php echo $tangkap['Tahun_Rilis']; ?></td>
<td><a href="daftarbuku.php?delete=true&id=<?php echo $tangkap['Isbn']; ?>">- Hapus</a> |
<a href="edit.php?id=<?php echo $tangkap['Isbn']; ?>"> Edit</a></td>
</tr>
<?php
}
?>
</table>

</body>
</html>
Cari.php
<?php
include "koneksi.php";
?>
<html>
<link href="framelayout.css" rel="stylesheet" type="text/css" />
<body>
<table class="buku" border="1">
<?php
if (isset($_POST['submit'])) {
$search = $_POST['txtCari'];

$sql = "SELECT * FROM buku WHERE Judul_Buku LIKE '%$search%'";


$result = mysqli_query($kons, $sql);
$hasil=mysqli_query($kons, "SELECT * FROM buku");
echo "
<tr>
<th width='50'>Isbn</th>
<th width='100'>Judul Buku</th>
<th width='100'>Penulis</th>
<th width='100'>Penerbit</th>
<th width='100'>Tahun Rilis</th>
</tr>";
if (mysqli_num_rows($result) == 0) {
echo '<p></p><p>Pencarian tidak ditemukan</p>';
} else {
echo '<p></p>';
while ($row = mysqli_fetch_array($result)) {
echo "
<tr>
<td align='left'>$row[Isbn]</td>
<td align='left'>$row[Judul_Buku]</td>
<td align='left'>$row[Penulis]</td>
<td align='left'>$row[Penerbit]</td>
<td align='left'>$row[Tahun_Rilis]</td>
</tr>";
}

}
}
?>
</table>
</body>
</html>
Tambah.php
<?php
if (isset($_POST['judul'])) {
$Isbn = $_POST['Isbn'];
$judul = $_POST['judul'];
$penulis = $_POST['penulis'];
$penerbit = $_POST['penerbit'];
$tahun = $_POST['tahun'];

include 'koneksi.php';

mysqli_query($kons, "INSERT INTO `buku`(`Isbn`,`Judul_Buku`, `Penulis`, `Penerbit`,


`Tahun_Rilis`) VALUES ('$Isbn','$judul','$penulis','$penerbit','$tahun')");

echo "<script> alert('Buku Ditambahkan Broo');</script>";


}
?>
<form action="#" method="POST">
<table>
<tr>
<td>ISBN</td>
<td>:</td>
<td><input type="text" name="Isbn" required></td>
</tr>
<tr>
<td>Judul</td>
<td>:</td>
<td><input type="text" name="judul" required></td>
</tr>

<tr>
<td>Penulis</td>
<td>:</td>
<td><input type="text" name="penulis" required></td>
</tr>

<tr>
<td>Penerbit</td>
<td>:</td>
<td><input type="text" name="penerbit" required></td>
</tr>

<tr>
<td>Tehun Rilis</td>
<td>:</td>
<td><input type="number" name="tahun" required></td>
</tr>

<tr>
<td colspan="3"><button type="submit" style="width: 100%;">+
Tambah</button></td>
</tr>
</table>
</form>
Edit.php
<?php
include 'koneksi.php';

$idx = $_GET['id'];

$gas = mysqli_query($kons, "SELECT * FROM buku WHERE Isbn = '$idx'");


$data = mysqli_fetch_array($gas);

if (isset($_POST['judul'])) {
$judul = $_POST['judul'];
$penulis = $_POST['penulis'];
$penerbit = $_POST['penerbit'];
$tahun = $_POST['tahun'];

mysqli_query($kons, "UPDATE `buku` SET


`Judul_Buku`='$judul',`Penulis`='$penulis',`Penerbit`='$penerbit',`Tahun_Rilis`='$tahun' WHERE Isbn = '$idx'");

echo "<script> alert('Buku Diubah Bangsat'); document.location='daftarbuku.php'; </script>";

}
?>
<form action="#" method="POST">
<table>
<tr>
<td>Judul</td>
<td>:</td>
<td><input type="text" name="judul" value="<?php echo $data['Judul_Buku'] ?>"
required></td>
</tr>

<tr>
<td>Penulis</td>
<td>:</td>
<td><input type="text" name="penulis" value="<?php echo $data['Penulis'] ?>"
required></td>
</tr>

<tr>
<td>Penerbit</td>
<td>:</td>
<td><input type="text" name="penerbit" value="<?php echo $data['Penerbit'] ?>"
required></td>
</tr>

<tr>
<td>Tehun Rilis</td>
<td>:</td>
<td><input type="number" name="tahun" value="<?php echo $data['Tahun_Rilis'] ?>"
required></td>
</tr>

<tr>
<td colspan="3"><button type="submit" style="width: 100%;">+ Simpan
Perubahan</button></td>
</tr>
</table>
</form>

You might also like