<td>Kategori</td>
         	<td><select name="kategori">
			<option value=0 selected>- kategori -</option> 
			<? 
			$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>

Hey, I am trying to create a combo box but receive this error when I run it:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\Masterlink\cgoods\product_edit.php on line 8

Why is it?

Recommended Answers

All 7 Replies

Well in your script you have forgotten to include the mysql_connect() and mysql_select_db() functions. Try adding them in at the appropriate places and also when using the php opening tag, use <?php instead of the short tag <? as some servers will not recognize the short tags.

I do have the <?php include ("includes/koneksi.php"); ?> already far above where I coded. Well, I change the error numbering system (adjusting to the post, instead of the real error).

In actual is error on line 112.

echo "<option value= $dataCOMBO['nama_kategori']>$dataCOMBO['nama_kategori']</option>";

The same error still remains after I correct the short tag to php opening tag.

Well the error is in a piece of code you haven't posted (before line 112 not posted) and is usually caused by a missing quote after a string. For example:

$variable = "this is wrong;
//30 lines later
echo "hello world";

That is what you have done in your script and you will need to find where you forgot the quote. Unfortunately php does not report the line of the missing quote but rather the line that it causes problems which in my example would be line 3 instead of line 1.

Well, I think I find the errors:

I modify line 112 to :

echo "<option value=$dataCOMBO[nama_kategori]>$dataCOMBO[nama_kategori]</option>";
			}?>

I delete the array apostrope.

If you have solved it then please mark this thread as solved otherwise please post the full code.

A little bit more about the combo box if anyone can help me out before I solved the combo box problems:

product_edit.php

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

<?php 

$result = mysql_query("SELECT * FROM produk AS p, kategori AS k WHERE id_produk='".mysql_real_escape_string($_REQUEST['id'])."'AND p.id_kategori = k.id_kategori") or die(mysql_error());
$data = mysql_fetch_array($result);


?>

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

        <tr>
        	<td>Nama</td>
        	<td><input name="nama" type="text" value = <?php echo $data['nama_produk']; ?> size="20" />
        </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>

The problem with this code is it shows me the same kategori name twice:

Kategori : [ Sonny Ericssons ]
Nokia
Sonny Ericssons
Motorolla
LG
Samsung

The first one is the category name that is already picked. The next one are the whole list of category. Which ever product category I picked it always shows me the name twice. I would like the combo box select the category product name that I would like to edit without showing it twice. Is it possible?

For instance if it is on the second row then, select the second row if on other row then select the other row.

Try the following:

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

<?php 

$result = mysql_query("SELECT * FROM produk AS p, kategori AS k WHERE id_produk='".mysql_real_escape_string($_REQUEST['id'])."'AND p.id_kategori = k.id_kategori") or die(mysql_error());
$dataCOMBO = mysql_fetch_array($result);


?>

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

        <tr>
        	<td>Nama</td>
        	<td><input name="nama" type="text" value = "<?php echo $dataCOMBO['nama_produk']; ?>" size="20" />
        </tr>
        <tr>
        	<td>Kategori</td>
         	<td><select name="kategori"><option value="<?php echo $dataCOMBO['nama_kategori']; ?>" selected><?php echo $dataCOMBO['nama_kategori']; ?></option> 
			<?php 
			$resultCOMBO = mysql_query("SELECT nama_kategori FROM kategori WHERE id_produk!='".mysql_real_escape_string($_REQUEST['id'])."' OR p.id_kategori != k.id_kategori") or die(mysql_error());
			while($dataCOMBO = mysql_fetch_array($resultCOMBO)){
		         echo "<option value={$dataCOMBO['nama_kategori']}>{$dataCOMBO['nama_kategori']}</option>";
			}?>				 
			</select>            
            </td>

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