The following form if I press simpan (translate: save) suppose to save and insert all the data capture. but it does not. When I press save, it makes the form blank and none of the data being capture why is it?

product_edit.php

$nama = isset($_POST['nama']) ? $_POST['nama'] : '';	  
$kategori = isset($_POST['kategori']) ? $_POST['kategori'] : '';
$harga = isset($_POST['harga']) ? $_POST['harga'] : '';	  
$gambar = isset($_POST['gambar']) ? $_POST['gambar'] : '';	  
$deskripsi = isset($_POST['deskripsi']) ? $_POST['deskripsi'] : '';	  


// SETELAH TOMBOL SIMPAN DI TEKAN

if (isset($_GET['save'])){
		$nama = $_GET['nama'];
		$kategori = $_GET['kategori'];
		$harga = $_GET['harga'];
		$gambar = $_GET['gambar'];
		
		if (empty($_GET['id'])){
			$result = mysql_query("INSERT INTO produk(nama_produk, harga, gambar) VALUES('".$nama."','".$kategori."','".$gambar."')");
			}
		else{
			$result = mysql_query("UPDATE produk SET nama_produk='".$nama_produk."', harga='".$harga."', deskripsi='".$deskripsi."', gambar='".$gambar."' WHERE id=".$_GET['id']);
		$result = mysql_query($sqlstr) or die(mysql_error());
		
		//Jika mode edit, maka tidak akan dikirimkan konfirmasi kepada subscriber
		//if (empty($_REQUEST['id']))	kirimEmail($idKategori, $judul, $news);
		$confirmation = ($result) ? "Data telah tersimpan." : "Gagal menyimpan data.";	
		}
	}

?>
        
<h2><center>Product Preview</center></h2>
<p></p>

<?php 

$data = array();
if(!empty($_GET['id']))
	{
	$result = mysql_query("SELECT * FROM produk AS p, kategori AS k WHERE id_produk='".mysql_real_escape_string($_GET['id'])."'AND 			    p.id_kategori = k.id_kategori") or die(mysql_error());
    $data = mysql_fetch_array($result);
	echo '<pre>';
	print_r($data);
	echo '</pre>';
    }
else
	{
	$data['nama_produk'] = '';
	$data['nama_kategori'] = '';
	$data['harga'] = '';
	//$data['deskripsi'] = '';
	$data['gambar'] = '';
	//print_r($data);
	}		 

?>

<form method = "POST" enctype="multipart/formdata" action = "<?php $_SERVER['PHP_SELF']; ?>"> 
<table border="0" cellpadding="2">

        <tr>
        	<td>Nama</td>
        	<td><input name="nama" size="20px" type="text" value ="<?php echo $data['nama_produk']; ?>"/>
        </tr>
        <tr>
        	<td>Kategori</td>
         	<td><select name="kategori"><option value=<?php echo $data['nama_kategori']; ?> selected><?php echo $data['nama_kategori']; ?></option>
             			<?php 		
						
							$resultCOMBO = mysql_query("SELECT nama_kategori FROM kategori") or die(mysql_error());			while($dataCOMBO = mysql_fetch_array($resultCOMBO)){
							         echo "<option value={$dataCOMBO['nama_kategori']}>{$dataCOMBO['nama_kategori']}</option>";	
						}?>	
                </select>              
            </td>

       </tr>
        <tr>
        	<td>Harga</td>
            <td><input name="harga" type="text" value = <?php echo $data['harga']; ?>></td>
        </tr>
        <tr>
        	<td>Deskripsi</td>
            <td>
                    <textarea name="deskripsi" cols="30" rows="15"><?php echo isset($data['deskripsi']) ? $data['deskripsi'] : '';  ?></textarea></td>
                    <script type="text/javascript">
					var editor = CKEDITOR.replace('deskripsi');
			        </script>
        </tr>
        <tr>
        	<td>Gambar</td>
			<td><img src="foto_produk/<?php echo $data['gambar'];?>" width="30%" height="30%" /></td>            
        </tr>	
		<tr>
        	<td>Ganti Gambar</td>
            <td>
            <input name="gambar" type="file" value="Browse" /></td>
        </tr>	
        <tr>
        	<td></td>
            <td><br /><center><input name="save" type="submit" value="Simpan" /></center></td>
        </form>
        </tr>
        
	</tr>

first edit the form attribute enctype="" >>

enctype="multipart/form-data"

not enctype="multipart/formdata"

and then try and also check the Value that you getting through $_POST

$nama = isset($_POST['nama']) ? $_POST['nama'] : 'blank';

echo $nama;

you mean changing it to:

<form method = "POST" not enctype="multipart/formdata" action = "<?php $_SERVER['PHP_SELF']; ?>">

echo $nama;

captures and print out the value correctly as I input.

you mean changing it to:

<form method = "POST" not enctype="multipart/formdata" action = "<?php $_SERVER['PHP_SELF']; ?>">

echo $nama;

captures and print out the value correctly as I input.

noop

i mean

<form method="POST" enctype="multipart/form-data" action="<?php $_SERVER['PHP_SELF'];?>" >

I did it. but it does not make much difference. still unable to save the data that I entered.

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.