product_preview.php
// EDIT / DELETE MODE
$kategori = isset($_POST['kategori']) ? $_POST['kategori'] : '';
if(!empty($_POST['id']) && !empty($_POST['mode'])){
if(!$_POST['mode'] == 'edit'){
$output = mysql_query("SELECT * FROM kategori WHERE id=".$_POST['id']) or die(mysql_error());
$data = mysql_fetch_array($output);
$kategori = $data['nama_kategori'];
echo $kategori;
}
elseif(!$_POST['mode'] == 'delete'){
$output = mysql_query("DELETE * FROM produk WHERE id=".$_POST['id']) or die(mysql_error());
$confirmation = $output ? "Data has been deleted" : "Fail to delete data";
}
}
?>
<h2><center>Product Preview</center></h2>
<p> <form method = "post" action = "product_edit.php" >
<p> <input name="tambah_produk" type="submit" value="Tambah Produk" /> </p>
</form>
<table border="1" cellpadding="2">
<tr>
<td>No </td>
<td>Nama Produk</td>
<td>Harga</td>
<td>Tgl Masuk</td>
<td>Aksi </td>
</tr>
<?php
include ("includes/koneksi.php");
$i = 1;
$output = mysql_query("SELECT * FROM produk") or die(mysql_error());
while($data = mysql_fetch_array($output)){
?>
<tr>
<td><?php echo $i."</br>";?>
<td><?php echo $data['nama_produk']."</br>";?></td>
<td><?php echo $data['harga']."</br>";?></td>
<td><?php echo date('j-M-Y',strtotime($data['tgl_masuk']))."</br>";?></td>
<td>
<a href="./product_edit.php?id=<?php echo $data['id_produk'];?>&mode=edit">Edit</a>
<a href="./product_preview.php?id=<?php echo $data['id_produk'];?>&mode=delete">Delete</a>
</td>
</tr>
<?php
$i++;
}
?>
When I press delete button, why nothing happens?
elseif(!$_POST['mode'] == 'delete'){
$output = mysql_query("DELETE * FROM produk WHERE id=".$_POST['id']) or die(mysql_error());
$confirmation = $output ? "Data has been deleted" : "Fail to delete data";
should I use $_POST or $_GET ?