0

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++;	
	}

	?>

Edited by davy_yg: n/a

1
Contributor
1
Reply
4
Views
6 Years
Discussion Span
Last Post by davy_yg
0

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.