COM
a. Tabel t_barang
b. Tabel t_produk
c. Tabel t_transaksi
1
KURSUS-IT.COM
<html>
<head>
<title>Latihan Crud</title>
</head>
<body>
<h1><b>Latihan Create-Read-Update-Delete (CRUD)</b></h1>
<ul>
<li><b>Tambah</b>
<ul>
<li><a href="Produk/frm_produk.php">Produk</a></li>
<li><a href="Barang/frm_barang.php">Barang</a></li>
<li><a href="Transaksi/frm_transaksi.php">Transaksi</a></li>
</ul>
</li>
<li><b>Menampilkan Data</b>
<ul>
<li><a href="Produk/view_produk.php">Produk</a></li>
<li><a href="Barang/view_barang.php">Barang</a></li>
<li><a href="Transaksi/view_transaksi.php">Transaksi</a></li>
</ul>
</li>
</ul>
</body>
</html>
2
KURSUS-IT.COM
2. Script simpan_produk.php
<?php
include '../koneksi.php';
$kd = $_POST['kdproduk'];
$nm = $_POST['nmproduk'];
3
KURSUS-IT.COM
3. Script view_produk.php
<html>
<head>
</head>
<body>
<h1><b>VIEW PRODUK</b></h1>
<hr style="border:1px dotted #f00; width:100%"; ">
<table width="600" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th align="center"><b>No</b></th>
<th align="center"><b>Kode Produk</b></th>
<th align="center"><b>Nama Produk</b></th>
<th align="center" colspan="2"><b>Aksi</b></th>
</tr>
</thead>
<tbody>
<?php
include '../koneksi.php';
$no = 1;
$sql = mysqli_query($koneksi,"select * from t_produk order by
kdproduk");
while($rs = mysqli_fetch_array($sql)){
echo "
<tr>
<td align='center'>$no</td>
<td align='center'>$rs[kdproduk]</td>
<td align='center'>$rs[nmproduk]</td>
<td align='center'>
<a
href='edit_produk.php?id=$rs[id]'>Edit</a>
</td>
<td align='center'>
<a
href='hapus_produk.php?id=$rs[id]'>Hapus</a>
</td>
</tr>";
4
KURSUS-IT.COM
$no++;
}
?>
</tbody>
</table>
<br>
<td><a href='../index.php'>KEMBALI</a></td>
</body>
</html>
4. Script edit_produk.php
<?php
include '../koneksi.php';
$id = $_GET['id'];
$sql = mysqli_query($koneksi,"select * from t_produk where id = '$id'");
$rs = mysqli_fetch_array($sql);
?>
<html>
<head>
</head>
<body>
<h1><b>EDIT PRODUK</b></h1>
<hr style="border:1px dotted #f00; width:100%; ">
<form method="post" action="update_produk.php">
<table>
<tr>
<td>Kode Produk</td>
<td><input type="text" name="kdproduk" value="<?php echo
$rs['kdproduk'] ?>"></td>
</tr>
<tr>
<td>Nama Produk</td>
<td><input type="text" name="nmproduk" size="25" value="<?php
echo $rs['nmproduk'] ?>"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="simpan" value="SIMPAN" ></td>
</tr>
</table>
</form>
<td><a href='view_produk.php'>KEMBALI</a></td>
</body>
</html>
5. Script hapus_produk.php
<?php
include '../koneksi.php';
5
KURSUS-IT.COM
$id = $_GET['id'];
6. Script update_produk.php
<?php
include '../koneksi.php';
$kd = $_POST['kdproduk'];
$nm = $_POST['nmproduk'];
6
KURSUS-IT.COM
1. Script frm_barang.php
<html>
<head>
</head>
<body>
<h1><b>DATA BARANG</b></h1>
<hr style="border:1px dotted #f00; width:100%; ">
<form method="post" action="simpan_barang.php">
<table>
<tr>
<td>Kode Barang</td>
<td><input type="text" name="kdbarang" size="25" ></td>
</tr>
<tr>
<td>Nama Barang</td>
<td><input type="text" name="nmbarang" size="25" ></td>
</tr>
<tr>
<td>Stok Barang</td>
<td><input type="text" name="stok" size="25" ></td>
</tr>
<tr>
<td>Harga Barang</td>
<td><input type="text" name="harga" size="25" ></td>
</tr>
<tr>
<td>Kode Produk</td>
<td><input type="text" name="kdproduk" size="25" ></td>
</tr>
<tr>
<td> </td>
7
KURSUS-IT.COM
2. Script simpan_barang.php
<?php
include '../koneksi.php';
$kd = $_POST['kdbarang'];
$nm = $_POST['nmbarang'];
$st = $_POST['stok'];
$hg = $_POST['harga'];
$kdp = $_POST['kdproduk'];
3. Script view_barang.php
<html>
<head>
8
KURSUS-IT.COM
</head>
<body>
<h1><b>VIEW BARANG</b></h1>
<hr style="border:1px dotted #f00; width:100%"; ">
<table width="600" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th align="center"><b>No</b></th>
<th align="center"><b>Kode Barang</b></th>
<th align="center"><b>Nama Barang</b></th>
<th align="center"><b>Stok Barang</b></th>
<th align="center"><b>Harga Barang</b></th>
<th align="center"><b>Kode Produk</b></th>
<th align="center" colspan="2"><b>Aksi</b></th>
</tr>
</thead>
<tbody>
<?php
include '../koneksi.php';
$no = 1;
$sql = mysqli_query($koneksi,"select * from t_barang order by
kdbarang");
while($rs = mysqli_fetch_array($sql)){
echo "
<tr>
<td align='center'>$no</td>
<td align='center'>$rs[kdbarang]</td>
<td align='center'>$rs[nmbarang]</td>
<td align='center'>$rs[stok]</td>
<td align='center'>$rs[harga]</td>
<td align='center'>$rs[kdproduk]</td>
<td align='center'>
<a
href='edit_barang.php?id=$rs[id]'>Edit</a>
</td>
<td align='center'>
<a
href='hapus_barang.php?id=$rs[id]'>Hapus</a>
</td>
</tr>";
$no++;
}
?>
</tbody>
</table>
<hr style="border:1px dotted #f00; width:100%"; ">
<br>
<td><a href='../index.php'>KEMBALI</a></td>
</body>
</html>
9
KURSUS-IT.COM
4. Script edit_barang.php
<?php
include '../koneksi.php';
$id = $_GET['id'];
$sql = mysqli_query($koneksi,"select * from t_barang where id = '$id'");
$rs = mysqli_fetch_array($sql);
?>
<html>
<head>
</head>
<body>
<h1><b>EDIT BARANG</b></h1>
<hr style="border:1px dotted #f00; width:100%; ">
<form method="post" action="update_barang.php">
<table>
<tr>
<td>Kode Barang</td>
<td><input type="text" name="kdbarang" size="25" value="<?php
echo $rs['kdbarang'] ?>"></td>
</tr>
<tr>
<td>Nama Barang</td>
<td><input type="text" name="nmbarang" size="25" value="<?php
echo $rs['nmbarang'] ?>"></td>
</tr>
<tr>
<td>Stok Barang</td>
<td><input type="text" name="stok" size="25" value="<?php echo
$rs['stok'] ?>"></td>
</tr>
<tr>
<td>Harga Barang</td>
<td><input type="text" name="harga" size="25" value="<?php
echo $rs['harga'] ?>"></td>
</tr>
<tr>
<td>Kode Produk</td>
<td><input type="text" name="kdproduk" size="25" value="<?php
echo $rs['kdproduk'] ?>"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="simpan" value="SIMPAN" ></td>
</tr>
</table>
</form>
<td><a href='view_barang.php'>KEMBALI</a></td>
</body>
</html>
10
KURSUS-IT.COM
5. Script hapus_barang.php
<?php
include '../koneksi.php';
$id = $_GET['id'];
6. Script update_barang.php
<?php
include '../koneksi.php';
$kd = $_POST['kdbarang'];
$nm = $_POST['nmbarang'];
$st = $_POST['stok'];
$hg = $_POST['harga'];
$kdp = $_POST['kdproduk'];
11
KURSUS-IT.COM
1. Script frm_transaksi.php
<?php
include '../koneksi.php';
$barang=mysqli_query($koneksi,"select * from t_barang order by id");
$ba=mysqli_fetch_array($barang);
$transaksi=mysqli_query($koneksi,"select * from t_transaksi order by no_faktur");
$tr=mysqli_fetch_array($transaksi);
?>
<html>
<head>
</head>
<body>
<h1><b>DATA TRANSAKSI</b></h1>
<hr style="border:1px dotted #f00; width:100%; ">
<form method="post" action="simpan_transaksi.php">
<table>
<tr>
<td>Tanggal Faktur</td>
<td><input type="date" name="tgfaktur" size="25" ></td>
</tr>
<tr>
<td>Kode Barang</td>
<td><input type="text" name="kdbarang" size="25" ></td>
</tr>
<tr>
<td>Jumlah Transaksi</td>
<td><input type="text" name="jumlah" size="25" ></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="simpan"
value="SIMPAN" ></td>
</tr>
</table>
</form>
12
KURSUS-IT.COM
2. Script simpan_transaksi.php
<?php
include '../koneksi.php';
$tf = $_POST['tgfaktur'];
$kd = $_POST['kdbarang'];
$jh = $_POST['jumlah'];
$barang=mysqli_query($koneksi,"select * from t_barang where kdbarang = '$kd'");
$ba=mysqli_fetch_array($barang);
$th = $jh*$ba['harga'];
if ($ba['stok'] >= 1) {
$so = $ba['stok']-$jh;
}
3. Script view_transaksi.php
<html>
<head>
</head>
<body>
13
KURSUS-IT.COM
<h1><b>VIEW TRANSAKSI</b></h1>
<hr style="border:1px dotted #f00; width:100%"; ">
<table width="600" border="1" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th align="center"><b>No</b></th>
<th align="center"><b>Tanggal Faktur</b></th>
<th align="center"><b>Kode Barang</b></th>
<th align="center"><b>Jumlah</b></th>
<th align="center"><b>Total Harga</b></th>
<th align="center" colspan="2"><b>Aksi</b></th>
</tr>
</thead>
<tbody>
<?php
include '../koneksi.php';
$no = 1;
$sql = mysqli_query($koneksi,"select * from t_transaksi
order by
tgl_faktur");
while($rs = mysqli_fetch_array($sql)){
echo "
<tr>
<td align='center'>$no</td>
<td align='center'>$rs[tgl_faktur]</td>
<td align='center'>$rs[kdbarang]</td>
<td align='center'>$rs[jumlah]</td>
<td align='center'>$rs[total]</td>
<td align='center'>
<a
href='edit_transaksi.php?tgl=$rs[tgl_faktur]'>Edit</a>
</td>
<td align='center'>
<a
href='hapus_transaksi.php?tgl=$rs[tgl_faktur]'>Hapus</a>
</td>
</tr>";
$no++;
}
?>
</tbody>
</table>
<br>
<td><a href='../index.php'>KEMBALI</a></td>
</body>
</html>
14