now we will make a simple add, edit ,delete data with jquery, php and mysql
first we create a table called ‘tbl_barang’
CREATE TABLE `tbl_barang` (
`kode_barang` varchar(10) collate latin1_general_ci NOT NULL,
`nama_barang` varchar(100) collate latin1_general_ci NOT NULL,
`harga` double(16,2) NOT NULL,
PRIMARY KEY (`kode_barang`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;
after that we create a file called ‘koneksi.php’ and put ths code into the file
<?
mysql_connect("localhost","root","") or die("maaf, tidak berhasil konek ke database");
mysql_select_db("myblog") or die("database tidak ada");
?>
then let’s create a file to view a list of inserted data give the file name “listbarang.php” and put this code into the file.
<?
include("koneksi.php");
$str="select * from tbl_barang";
$res=mysql_query($str) or die("query gagal dijalankan");
?>
<table width="100%" border="1" cellpadding="5" cellspacing="0">
<thead>
<tr bgcolor="#CCCCCC">
<th>Kode barang</th><th>Nama barang</th><th>Harga</th><th width="50">Edit</th><th width="50">delete</th>
</tr>
</thead>
<tbody>
<? while($data=mysql_fetch_assoc($res)){?>
<tr>
<td><? echo $data['kode_barang'];?></td><td><? echo $data['nama_barang'];?></td><td><? echo $data['harga'];?></td><td><a href="formbarang.php?action=update&kodebarang=<? echo $data['kode_barang'];?>">edit</a></td><td><a href="proses.php?action=delete&kodebarang=<? echo $data['kode_barang'];?>">delete</a></td>
</tr>
<? }?>
</tbody>
</table>
Continue reading ‘Ajax Create, update and delete data with jquery and php’