hi guys, i have working on this simple cart script,it goes like when selecting the product in combobox it will display the details of the
product into the textbox, i can display the details but my problem is when i select another product the previous
selected product was replaced.. what should i do to keep the selected first,second.. and so on product in the form? thanks
my script so far...
<html>
<head>
</head>
<body>
<form action="insert.php" method="post">
<?php
mysql_connect("localhost","root","");
mysql_select_db("Inventory") or die(mysql_error());
$sql="SELECT * FROM product order by id";
$query=mysql_query($sql);
echo "<select name='select' size='5'>";
while($row = mysql_fetch_array($query))
{
if ($_POST['select'] == $row['id']){
$pquan=$row['pquan'];
$sel=$row['sellprice'];
$pcode = $row['pcode'];
}
$selected = '';
if (isset($_POST['select']) && strcmp($row['id'], $_POST['select']) == 0)
{
$selected = ' selected="selected"';
}
printf ('<option value="%s"%s>%s</option>'. PHP_EOL, $row['pname'], $selected, $row['pname']);
}
echo "</optgroup>";
?>
</select>
<?php
if ($_POST['submit'])
{
$i = $_POST['count'];
for ($x=0;$x<=$i;$x++)
{
?>
<br>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo htmlspecialchars(@$_POST['select']); ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo $pcode ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo $pquan ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" value="<?php echo $sel ?>" size=5/>
<input type="text" name="textbox<?php echo $x; ?>" size=5/>
<input type="submit" name="delete" value="Delete" />
<?php
}
$i++;
?>
<input type="hidden" name="count" value="<?php echo $i; ?>" />
<?php
}
else
{
?>
<input type="hidden" name="count" value="0" />
<?php
}
$i--
?>
<br>
<input type="submit" name="submit" value ="Add Text Box" />
</form>
</body>
</html>