product_preview.php

<?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 telah terdelete" : "Gagal menghapus 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 $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++;	
	}

	?>

    
 
   <?php include('includes\footer.php'); ?>

    
<p>&nbsp;</p>
</body>
</html>

I would like to delete data, but the delete link does not work. I wonder what should I put for form action since if I press edit, I would like the form to carry me to product_edit form, if I press delete it remains in product_preview.php

The form preview:

No Nama_Produk Harga Tgl_Masuk Aksi
1 Motorola RAZR 2500000 2009-05-25 Edit Delete
2 Chocolate 3450000 2009-06-02 Edit Delete
3 Samsung 4500000 2009-06-02 Edit Delete

Hello,

Your 'edit' and 'delete' links call an URL with arguments 'mode' and 'id' passed using the GET method not the post method. Clicking on these links does not submit the form.
Therefore, use $_GET and $_GET instead of $_POST and $_POST

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.