0
<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?

2
Contributors
7
Replies
8
Views
6 Years
Discussion Span
Last Post by cwarn23
0

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.

0

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.

Edited by davy_yg: n/a

0

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.

0

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.

0

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

0

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.

Edited by davy_yg: n/a

0

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>

Edited by cwarn23: n/a

This topic has been dead for over six months. 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.