[go: up one dir, main page]

0% found this document useful (0 votes)
122 views7 pages

Crud

The document contains PHP code for a book database application. It includes files for connecting to a database, displaying book data in a table on an index page, and forms to add, edit and delete books. The form.php file contains a form to either add or edit a book depending on whether an ID is passed as a GET parameter. Data can be inserted into or updated in the database table using the functions in tambah.php and ubah.php respectively.

Uploaded by

Resdiyant Gank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
122 views7 pages

Crud

The document contains PHP code for a book database application. It includes files for connecting to a database, displaying book data in a table on an index page, and forms to add, edit and delete books. The form.php file contains a form to either add or edit a book depending on whether an ID is passed as a GET parameter. Data can be inserted into or updated in the database table using the functions in tambah.php and ubah.php respectively.

Uploaded by

Resdiyant Gank
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

form.

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'])){?>

<input type="submit" name="Submit" value="Tambah">


<?php }
else{?>
<input type="submit" name="Submit" value="Simpan">
<?php } ?>

</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");

$seleksi = "SELECT * FROM buku order by id";


$hasil_seleksi = mysql_query ($seleksi);

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";

$selek_db = mysql_select_db ($database);


if (!$selek_db) {
die ("Database tidak terseleksi");
}
?>
TAMBAH.php

<?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>

You might also like