You are on page 1of 3

Koneksi Database <?php $host = "127.0.0.

1"; $user = "root"; $pass = ""; $koneksi = mysql_connect($host, $user, $pass); mysql_select_db('data_barang', $koneksi) or die(mysql_error()); ?>

TampilBarang <?php include "koneksi.php";

$q = "select*from barang"; $ex = mysql_query($q); $h ="Jumlah*Harga"; echo "<a href='addbarang.php'>Tambah Barang</a>"; echo "<table border=1>"; echo "<tr> <th>Kode_Barang</th><th>Nama_Barang</th><th>Jumlah</th><th>Harga</th> <th>Total_Harga</th><th>Action</th></tr>"; while($r = mysql_fetch_array($ex)){ echo "<tr><td>".$r['Kode_Barang']."</td>"; echo "<td>".$r['Nama_Barang']."</td>"; echo "<td>".$r['Jumlah']."</td>"; echo "<td>".$r['Harga']."</td>"; echo "<td>".$r['Total_Harga']."</td>";

echo "<td><a href='editbarang.php?n=".$r['Kode_Barang']."'>Ubah</a>"; echo "<a href='deletebarang.php?n=".$r['Kode_Barang']."'>Hapus</a>"; echo "</td></tr>"; } echo "</table>"; ?>

addBarang <?php include "koneksi.php"; ?> <form action="#" method="post"> Kode_Barang: <input type="text" name="tKode_Barang"/><br/> Nama_Barang: <input type="text" name="tNama_Barang"/><br/> Jumlah: Harga: <br> <input type="submit" name="bok" value="Simpan"/> </form> <a href="tampilbarang.php">Kembali ...</a> <?php if(isset($_POST['bok'])){ $Kode_Barang=$_POST['tKode_Barang']; $Nama_Barang=$_POST['tNama_Barang']; $Jumlah=$_POST['tJumlah']; $Harga=$_POST['tHarga']; $Total_Harga = $Jumlah * $Harga; $q="insert into barang(Kode_Barang,Nama_Barang,Jumlah,Harga,Total_Harga) values ('$Kode_Barang','$Nama_Barang','$Jumlah','$Harga','$Total_Harga')"; mysql_query($q); echo "Data Tersimpan"; } ?> <input type="text" name="tJumlah"/><br/> <input type="text" name="tHarga"/><br/>

editBarang <?php include "koneksi.php"; $Kode_Barang = $_GET['n']; $q = "select * from barang where Kode_Barang='$Kode_Barang'"; $ex = mysql_query($q); $r = mysql_fetch_array($ex); ?> <form action="#" method="post">

Kode_Barang : <input type="text" name="tKode_Barang" value="<?php echo $r['Kode_Barang']; ?>"/><br/> Nama_Barang : <input type="text" name="tNama_Barang" value="<?php echo $r['Nama_Barang']; ?>"/><br/> Jumlah : <input type="text" name="tJumlah" value="<?php echo $r['Jumlah']; ?>"/><br/> Harga : <input type="text" name="tHarga" value="<?php echo $r['Harga']; ?>"/><br/> <input type="submit" name="bok" value="Ubah Data"/> </form> <a href="tampilbarang.php">Kembali ...</a>

<?php if(isset($_POST['bok'])){ $Kode_Barang = $_POST['tKode_Barang']; $Nama_Barang = $_POST['tNama_Barang']; $Jumlah = $_POST['tJumlah']; $Harga = $_POST['tHarga']; $Total_Harga=$Jumlah * $Harga; $q = "update barang set Nama_Barang='$Nama_Barang', Jumlah='$Jumlah', Harga='$Harga', Total_Harga='$Total_Harga' where Kode_Barang='$Kode_Barang'"; mysql_query($q); echo "Data berhasil diubah"; } ?> deleteBarang <?php include "koneksi.php"; $Kode_Barang = $_GET['n']; $q = "delete from barang where Kode_Barang='$Kode_Barang'"; mysql_query($q); echo "Data Terhapus\n"; echo "<a href='tampilbarang.php'>kembali ...</a>"; ?>

You might also like