Pages

Wednesday, December 19, 2018

12

1. formtambah.php
<html><head>
<title>Input Data Barang</title>
</head><body>
<h2>Tambah Barang</h2>
<form action="simpan.php" method="POST">
<table><tr>
<td>Kode Barang</td>
<td>: <input type="text" name="kode" size="10"></td>
</tr>
<tr>
<td>Nama Barang</td>
<td>: <input type="text" name="namabarang" size="30"></td>
</tr>
<tr>
<td>Harga Satuan</td>
<td>: <input type="text" name="harga" size="20"></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Kirim"></td>
</tr></table></form>
</body></html>

2. simpan.php
<?php ob_start();
include "koneksi.php";

$kode   = $_POST['kode'];
$nama   = $_POST['namabarang'];
$harga  = $_POST['harga'];

mysql_query("INSERT INTO barang(kode,namabarang,harga)
VALUE('$kode','$nama','$harga')")or die(mysql_error());
header('location:tampil.php');
?>

3. formedit.php
<?php
include "koneksi.php";
$kode=$_GET['kode'];
$query=mysql_query("select * from barang where kode='$kode'");
?>
<html><head><title>Halaman Edit Data Barang</title><head><body>
<form action="edit.php" method="post">
<table border="0">
<?php
while($row=mysql_fetch_array($query)){
?>
<input type="Hidden" name="no" value="<?php echo $no;?>" />
<h2>Edit Barang</h2>
<table><tr>
<td>Kode Barang</td>
<td>: <input type="text" name="kode" value="<?php echo $row['kode'];?>" size="10"></td>
</tr>
<tr>
<td>Nama Barang</td>
<td>: <input type="text" name="namabarang" value="<?php echo $row['namabarang'];?>"size="30"></td>
</tr>
<tr>
<td>Harga Satuan</td>
<td>: <input type="text" name="harga" value="<?php echo $row['harga'];?>"size="20"></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Update"></td>
</tr>
<?php } ?>
</table></form>

</body></html>

4. edit.php
<?php ob_start();
include "koneksi.php";
$kode    = $_POST['kode'];
$nama    = $_POST['namabarang'];
$harga   = $_POST['harga'];

$query=mysql_query("update barang set kode='$kode', namabarang='$nama', harga='$harga' where kode='$kode'");
header('location:tampil.php');
?>

5. koneksi.php
<?php 
$server= "localhost"; 
$username = "root"; 
$password = ""; 
$database = "stmikj"; 
 
mysql_connect($server,$username,$password) or die ("Koneksi Gagal"); 
 
mysql_select_db($database) or die ("Database Tidak Bisa Di Buka " ); 
 
?>

6. hapus.php
<?php ob_start();
 include "koneksi.php";
 mysql_query("delete from barang where kode='$_GET[kode]'");
 header('location:tampil.php');

?>

7. tampil.php
<?php
include "koneksi.php";
include "formtambah.php";
echo "<center><table border=1><tr bgcolor=orange>
<td><b><center>No</td>
<td><b><center>Kode Barang</td>
<td><b><center>Nama Barang</td>
<td><b><center>Harga Satuan</td>
<td><b><center>Delete</td>
<td><b><center>Edit</td>
</tr>";
$query=mysql_query("SELECT * FROM barang ORDER BY kode");
$no=1;
while($var=mysql_fetch_array($query)){
echo "<tr>
<td>$no</td>
<td>$var[kode]</td>
<td>$var[namabarang]</td>
<td>$var[harga]</td>
<td><center><a href='hapus.php?kode=$var[kode]'>Delete</a></td>
<td><center><a href='formedit.php?kode=$var[kode]'>Edit</a></center></td>
</tr>";
$no++;
}
echo "</table>";
?>



======
Sumber: internet
Bitcoin Offers:
Free Bitcoin, Double Bitcoin, Bitcoin Investment, Bitcoin Trading



"Bitcoin and Forex are high risk business. We must join them smartly."

No comments:

Post a Comment