<html>
<head>
<title></title>
</head>
<body>
<?php
$sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("momo") or die ("Gagal membuka database.");
?>
<p align="left"> Data barang</p>
<table border="1" align="left">
<tr align="left">
<td>kode</td>
<td>Nama</td>
<td>harga</td>
<td>stok</td>
<td>plihan</td>
</tr>
<?php
$query = "select * from databarang";
$result = mysql_query($query, $sambung) or die("gagal melakukan query"); while ($buff = mysql_fetch_array($result)) {
?>
<tr>
<td><?php echo $buff['kode']; ?></td>
<td><?php echo $buff['nama']; ?></td>
<td><?php echo $buff['harga']; ?></td>
<td><?php echo $buff['stok']; ?></td>
<td><a href="../belajar/edit.php?kode=<?php echo $buff['kode']; ?>">Edit</a> |
<a href="../belajar/hapus.php?kode=<?php echo $buff['kode'];?>">Hapus</a></td>
</tr>
<?php
};
mysql_close($sambung);
?>
</table>
</br>
</br>
</br>
</br>
</br>
<p align="left"><a href="../belajar/form_tambah_data.php">Tambah Data</a></p>
</body>
</html>
- nama file: form_tambah_data.php
<html>
<head>
<title></title>
</head
<body>
<form name="form1" method="post" action="../belajar/tambah_data.php">
<p align="left"> Masukan Data barang</p>
<table boder="0" cellspacing="0" style="borde-cellsapcing":collapse" bordercolor="#111111" width="100%">
<tr>
<td width="16%">KODE</td>
<td width="84%"><input type="text" name="kode" size="29"></td>
</tr>
<tr>
<td width="16%">NAMA</td>
<td width="84%"><input type="text" name="nama" size="29"></td>
</tr>
<tr>
<td width="16%">HARGA</td>
<td width="84%"><input type="text" name="harga" size="29"></td>
</tr>
<tr>
<td width="16%">STOK</td>
<td width="84%"><input type="text" name="stok" size="29"></td>
</tr>
<tr>
<td width="16%"></td>
<td width="84%"><input type="submit" name="submit" size="29" value="SIMPAN"></td>
</tr>
</table>
</form>
<p> Untuk melihat data yang sudah tersimpan, Silahkan cek di <a href="../belajar/tampil.php">Tabel Data</a></p>
</table>
</body>
</html>
- nama file: tambah_data.php
<html>
<head>
<title></title>
</head>
<body>
<?php
$sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("momo") or die ("Gagal membuka database.");
$kode = $_POST['kode'];
$nama = $_POST['nama'];
$harga = $_POST['harga'];
$stok = $_POST['stok'];
$query = mysql_query("insert into databarang values ('$kode', '$nama', '$harga','$stok')");
//$sql = "insert into dataalamat (id, nama, alamat, kodepos, negara, telepon)
//values = ('', '$_POST[id]', '$_POST[nama]', '$_POST[alamat]', '$_POST[kodepos]', '$_POST[negara]', '$_POST[telepon]')";
//$result = mysql_query($sql, $sambung) or die("gagal melakukan query");
mysql_close($sambung);
?>
<p> Data sudah tersimpan, Silahkan cek di <a href="../belajar/tampil.php">Tabel Data</a></p>
</body>
</html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("momo") or die ("Gagal membuka database.");
$kode = $_GET['kode'];
$query = "select *from databarang where kode='$kode'";
$result = mysql_query($query, $sambung) or die("gagal melakukan query");
$buff = mysql_fetch_array($result);
mysql_close($sambung);
?>
<form name="form1" method="post" action="edit_data.php">
<p align="left"> Edit Data</p>
<table boder="0" cellspacing="0" style="borde-cellsapcing":collapse" bordercolor="#111111" width="100%">
<tr>
<td width="16%">kode</td>
<td width="84%"><input type="hidden" name="kode" value="<?php echo $buff['kode']; ?>" size="29"></td>
</tr>
<tr>
<td width="16%">Nama</td>
<td width="84%"><input type="text" name="nama" value="<?php echo $buff['nama']; ?>" size="29"></td>
</tr>
<tr>
<td width="16%">Harga</td>
<td width="84%"><input type="text" name="harga" value="<?php echo $buff['harga']; ?>" size="29"></td>
</tr>
<tr>
<td width="16%">Stok</td>
<td width="84%"><input type="text" name="stok" value="<?php echo $buff['stok']; ?>" size="29"></td>
</tr>
<tr>
<td width="16%"></td>
<td width="84%"><input type="submit" name="submit" size="29" value="SIMPAN"></td>
</tr>
</table>
</form>
<p> Batal mengedit data. kembali ke <a href="tampil.php">Tabel Data</a></p>
<body>
</body>
</html>
<html>
<head>
<title></title>
</head>
<body>
<?php
$sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("momo") or die ("Gagal membuka database.");
$kode = $_POST['kode'];
$nama = $_POST['nama'];
$harga = $_POST['harga'];
$stok = $_POST['stok']
$query = mysql_query("update databarang set nama='$nama', harga='$harga', stok='$stok' where kode='$kode'");
mysql_close($sambung);
?>
<p> Data sudah ter-update, Silahkan cek di <a href="tampil.php">Tabel Data</a></p>
</body>
</html>
<html>
<head>
<title>Menghapus Data</title>
</head>
<body>
<?php
$sambung = mysql_connect("localhost", "root", "") or die ("Gagal konek ke server.");
mysql_select_db("momo") or die ("Gagal membuka database.");
$kode = $_GET['kode'];
mysql_query("delete from databarang where kode='$kode'") or die ("Gagal menghapus data.");
mysql_close($sambung);
?>
<p> Data sudah dihapus, Silahkan cek di <a href="../belajar/tampil.php">Tabel Data</a></p>
</body>
</html>