Searching...
Selasa, 27 Mei 2014

Tutorial CRUD

13.28
Koneksi.php
<?php
$host = “localhost”;
$uname = “root”;
$pwd = “”;
$db = “toko”;
$uas = mysql_connect(“$host”, “$uname”, “$pwd”) or die (“gagal koneksi”);
mysql_select_db(“$db”, $uas) or die (“gagal koneksi ke database $db”);
?>
Input.php
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>Untitled Document</title>
</head>
<body>
<form name=”input” method=”post” action=”save.php”>
<table width=”329″ border=”1″>
<tr>
<td width=”147″>Kode Barang </td>
<td width=”8″ align=”center”>:</td>
<td width=”157″><input name=”kdbarang” type=”text” id=”kdbarang” /></td>
</tr>
<tr>
<td>Nama Barang </td>
<td align=”center”>:</td>
<td><input name=”nama” type=”text” id=”nama” /></td>
</tr>
<tr>
<td>Deskripsi</td>
<td align=”center”>:</td>
<td><input name=”des” type=”text” id=”des” /></td>
</tr>
<tr>
<td>Harga barang </td>
<td align=”center”>:</td>
<td><input name=”harga” type=”text” id=”harga” /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input name=”simpan” type=”submit” id=”simpan” value=”simpan” /></td>
</tr>
</table>
</form>
</body>
</html>
View.php
<?php
include”koneksi.php”;
$view = mysql_query(“select * from barang”);
echo”<table border=1>
<th>No.</th> <th>Kode Barang</th><th>Nama Barang</th><th>Deskripsi</th><th>Harga</th><th colspan=2>aksi</th>”;
while($v=mysql_fetch_array($view)){
$no++;
echo”
<tr>
<td>$no</td>
<td>$v[kdbarang]</td>
<td>$v[nama_barang]</td>
<td>$v[deskripsi]</td>
<td>$v[harga]</td>
<td><a href=edit.php?id=$v[kdbarang]>edit</a></td>
<td><a href=delete.php?id=$v[kdbarang]>delete</a></td>
</tr>”;
}
echo”<tr>
<td colspan=7><a href=input.php>INPUT DATA</a></td>
</tr>
</table>
“;
?>
Edit.php
<?php
include”koneksi.php”;
$id =$_GET['id'];
$edit =mysql_query(“select * from barang where kdbarang=’$id’”);
$e=mysql_fetch_array($edit);
?>
<form name=”input” method=”post” action=”update.php”>
<table width=”329″ border=”1″>
<tr>
<td width=”147″>Kode Barang </td>
<td width=”8″ align=”center”>:</td>
<td width=”157″><input name=”kdbarang” type=”text” id=”kdbarang” disabled=”disabled” value=”<?php echo”$e[kdbarang]“;?>”/> </td>
</tr>
<tr>
<td>Nama Barang </td>
<td align=”center”>:</td>
<td><input name=”nama” type=”text” id=”nama” value=”<?php echo”$e[nama_barang]“;?>” /></td>
</tr>
<tr>
<td>Deskripsi</td>
<td align=”center”>:</td>
<td><input name=”des” type=”text” id=”des” value=”<?php echo”$e[deskripsi]“;?>” /></td>
</tr>
<tr>
<td>Harga barang </td>
<td align=”center”>:</td>
<td><input name=”harga” type=”text” id=”harga” value=”<?php echo”$e[harga]“;?>” /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input name=”simpan” type=”submit” id=”simpan” value=”simpan” /></td>
</tr>
</table>
</form>
Update.php
<?php
include”koneksi.php”;
$kd =$_POST['kdbarang'];
$nama = $_POST['nama'];
$des =$_POST['des'];
$harga =$_POST['harga'];
$input = “update barang set kdbarang = ‘$kd’,
nama_barang = ‘$nama’,
deskripsi = ‘$des’,
harga = ‘$harga’
where kdbarang = ‘$kd’ “;
mysql_query(“$input”);
?>
<script type=”text/javascript”>
window.alert(“Update Sukses”);
window.location=”view.php”;
</script>
Delete.php
<?php
include”koneksi.php”;
$id =$_GET['id'];
$input = “delete from barang where kdbarang=’$id’”;
mysql_query(“$input”);
?>
<script type=”text/javascript”>
window.alert(“Data Telah di Hapus”);
window.location=”view.php”;
</script>


Comments
0 Comments

0 komentar:

Posting Komentar

Silahkan berkomenter tidak menggunakan SARA,SEX, dan POLITIK