Hey, out of the following codes:

product_edit.php

<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);
    }
else
	{
	$data['nama_produk'] = '';
	$data['nama_kategori'] = '';
	$data['harga'] = '';
	$data['deskripsi'] = '';
	$data['gambar'] = '';
	}		 

?>

<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" value= <?php echo $data['deskripsi']; ?></textarea>
                    <script type="text/javascript">
					var editor = CKEDITOR.replace('deskripsi');
			        </script> </td>
        </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="uploaded_file" type="file" value="Browse" /></td>
            </form>
        </tr>	
        <tr>
        	<td></td>
            <td><br /><center><input name="save" type="button" value="Simpan" /></center></td>
        </tr>
        
	</tr>

The output that has text area is filled with bunch of codes. I attached the pic. How to fix it ?

note: I am using ckeditor.

ending tags and string for values are missing

<input name="nama" size="20px" type="text" value =<?php echo $data['nama_produk']; ?>>

is supposed to be

<input name="nama" size="20px" type="text" value ="<?php echo $data['nama_produk']; ?>"/>

Well, I comment out line 19:

$data['deskripsi'] = '';

I have this error:
Notice: Undefined index: deskripsi in C:\xampp\htdocs\Masterlink\cgoods\product_edit.php on line 154

line 154:

<textarea name="deskripsi" cols="30" rows="15" value= <?php echo $data['deskripsi']; ?></textarea>

chnge line 12 from:

$data = mysql_fetch_array($result);

to

$data = mysql_fetch_array($result);
echo '<pre>';
print_r($data);
echo '</pre'>;

This will tell you how to access the data you are looking for...

The data appears if I press edit. It does not appears if I press new products.

This error: Notice: Undefined index: deskripsi in C:\xampp\htdocs\Masterlink\cgoods\product_edit.php on line 154 appears inside the ckeditor.

change 154 to:

<textarea name="deskripsi" cols="30" rows="15" value= <?php echo isset($data['deskripsi']) ? $data['deskripsi'] : '';  ?></textarea>

However I'd suggest checking your mysql query. It seems it must be turning some sort of bare result at the top because there seems to be a check there to see if its pulling info from the db if the id is set otherwise set all the variables as blank, which would be fine if it worked.

It does not work. Well, the top code query suppose to get id which is passed from the previous page if I press edit; otherwise, it suppose to set it to nothing (if press new product).

The error still the same as I attached.

you should no longer be getting the error when changing 154 to:

<textarea name="deskripsi" cols="30" rows="15" value= <?php echo isset($data['deskripsi']) ? $data['deskripsi'] : '';  ?></textarea>

this is checking to see if it's been set and if it hasn't displaying blank. are you sure your editing the correct file?


and then try changing it to this, and see what happens but note error supression isn't advised for use

<textarea name="deskripsi" cols="30" rows="15" value= <?php echo @isset($data['deskripsi']) ? $data['deskripsi'] : '';  ?></textarea>

make use of print_r each time you get that error and be sure that the mentioned index is part of array!

The value of a textarea should be between the tags, not in the value attribute:

<textarea>
textarea value goes here
</textarea>

Now it works. I do it like this:

<tr>
        	<td>Deskripsi</td>
            <td>
              <textarea name="deskripsi" cols="30" rows="15">
               <value= <?php echo isset($data['deskripsi']) ? $data['deskripsi'] : '';  ?>>

               </textarea></td>
                  <script type="text/javascript">
		var editor = CKEDITOR.replace('deskripsi');
		</script>
        </tr>

you can remove the "value=" in the textarea:

<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>
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.