product_category.php

I am writting the following codes. I would like in the input name Kategori value <?php $kategori; ?> to pull data from nama_kategori in kategori table (in phpmyadmin) whenever I press EDIT.

But this is not the case, whenever I press Edit the Kategori box value remains empty. Why is it?

Kategori [________________] [Simpan]

No Nama Kategori Aksi
1 Nokia EDIT DELETE


product_category.php

<?php include ("includes/koneksi.php"); ?>      
	 </div>     
        
<?php

// EDIT / DELETE MODE
$kategori = isset($_POST['kategori']) ? $_POST['kategori'] : '';	  

if(!empty($_REQUEST['id']) && !empty($_REQUEST['mode'])){
if(!$_REQUEST['mode'] == 'edit'){
	$output = mysql_query("SELECT * FROM kategori WHERE id=".$_REQUEST['id']) or die(mysql_error());
	$data = mysql_fetch_array($output);
	$kategori = $data['nama_kategori'];		
	echo $kategori;
	}
	elseif(!$_REQUEST['mode'] == 'delete'){
	$output = mysql_query("DELETE * FROM kategori WHERE id=".$_REQUEST['id']) or die(mysql_error());
	$confirmation = $output ? "Data telah terdelete" : "Gagal menghapus data"; 	
	}
}
?>        
        
        
        
        
<h2><center>Product Category</center></h2>

<form method="get" action="<?php $_SERVER['PHP_SELF']; ?>">
<p> Kategori : <input name="kategori" type="text" value="<?php echo $kategori;?>" size="20" />
<input name="Simpan" type="button" value="simpan" /></p>
</form>
<table border="1" cellpadding="2">
<tr>
	<td>No </td>
    <td>Nama Kategori </td>
    <td>Aksi </td>
</tr>
	<?php 
	include ("includes/koneksi.php");
	
	$i = 1;
	$output = mysql_query("SELECT * FROM kategori") or die(mysql_error());
	while($data = mysql_fetch_array($output)){
	?>

	<tr>
        	  <td><?php echo $i."</br>";?>
    	  <td><?php echo $data['nama_kategori']."</br>";?></td>
	  <td>
	   <a href="./product_category.php?id=<?php echo $data['id_kategori'];?>&mode=Edit">Edit</a>  
             <a href="./product_category.php?id=<?php echo $data['id_kategori'];?>&mode=Delete">Delete</a>
             </td>            	
        </tr>    

	
	<?php
	$i++;	
	}

	?>

Find the answer. CASE sensitive. I pass value with Capital letter.
];?>&mode=Edit">

And pull it with lowercase
if($_REQUEST == 'edit'){

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.