Crud
Crud
php
<?php if (empty($_GET['judul'])){?>
<form action="tambah.php" method="GET">
<?php }
else{?>
<form action="ubah.php" method="GET">
<?php }?>
<input name="id" id="id" type="hidden" value="<?php echo $_GET['id'];?>" >
<table >
<tr>
<td>Judul Buku</td>
<td><input name="judul" id="judul" type="text" value="<?php echo $_GET['judul'];?>" ></td>
</tr>
<tr>
<td>pengarang</td>
<td><input name="pengarang" id="pengarang" type="text" value="<?php echo $_GET['pengarang'];?>"
></td>
</tr>
<tr>
<td>penerbit</td>
<td><input name="penerbit" id="penerbit" type="text" value="<?php echo $_GET['penerbit'];?>" ></td>
</tr>
<tr>
<td>Tahun</td>
<td><input name="tahun" id="tahun" type="text" value="<?php echo $_GET['tahun'];?>" ></td>
</tr>
<tr>
<td align="center" colspan="2">
<?php if (empty($_GET['judul'])){?>
</td>
</tr>
</table>
</form>
hapus.php
<?php
include ("koneksi.php");
include ("seleksi_db.php");
$SQL="DELETE FROM buku WHERE id ='".$_GET['id']."';";
$cek = mysql_query($SQL, $koneksi) or die ("Proses update data GAGAL! <br> ");
?>
<script language="javascript">
alert("Data berhasil di hapus !!");
document.location.href="index.php";
</script>
index.php
<html>
<title>Menampilkan data ke dalam tabel</title>
<body>
<a href="from.php?"> tambah </a>
<table border="1">
<tr>
<th>Kode Buku</th>
<th>Judul Buku</th>
<th>pengarang</th>
<th>Penerbit</th>
<th>Tahun</th>
<td colspan="2">Action</td>
</tr>
<?php
include ("koneksi.php");
include ("seleksi_db.php");
if (!$hasil_seleksi){
echo "Proses penyeleksian tabel buku gagal !!!";
} else {
while ($baris = mysql_fetch_array ($hasil_seleksi)) {
echo "<tr>
<td>$baris[id]</td>
<td>$baris[judul]</td>
<td>$baris[pengarang]</td>
<td>$baris[penerbit]</td>
<td>$baris[tahun]</td>
<td><a
href='from.php?action=edit&id=$baris[id]&judul=$baris[judul]&pengarang=$baris[pengarang]&penerbit
=$baris[penerbit]&tahun=$baris[tahun]'> edit </a></td>
<td><a href='hapus.php?&id=$baris[id]'> hapus
</a></td>
<tr>";
};
};
?>
</table>
</body>
</html>
koneksi.php
<?php
$host = "localhost";
$user = "root";
$pass = "";
$koneksi = mysql_connect($host, $user, $pass);
if (!$koneksi) {
echo "Koneksi ke database gagal";
};
?>
Seleksi_db.php
<?php
include ("koneksi.php");
$database = "maxi";
<?php
include ("koneksi.php");
include ("seleksi_db.php");
$SQL="INSERT INTO buku (judul ,pengarang, penerbit, tahun)VALUES ( '".$_GET['judul']."',
'".$_GET['pengarang']."', '".$_GET['penerbit']."', '".$_GET['tahun']."');";
$cek = mysql_query($SQL, $koneksi) or die ("Proses update data GAGAL! <br> ");
?>
<script language="javascript">
alert("Data berhasil di Buat !!");
document.location.href="index.php";
</script>
Ubah.php
<?php
include ("koneksi.php");
include ("seleksi_db.php");
$SQL="UPDATE buku SET judul = '".$_GET['judul']."',pengarang = '".$_GET['pengarang']."',penerbit =
'".$_GET['penerbit']."',tahun= '".$_GET['tahun']."' WHERE id ='".$_GET['id']."';";
$cek = mysql_query($SQL, $koneksi) or die ("Proses update data GAGAL! <br> ");
//echo $SQL;
?>
<script language="javascript">
alert("Data berhasil di edit !!");
document.location.href="index.php";
</script>