Urgent! cart update method not working

Hi

I have a shopping cart where i can add, update and delete products. In this we can update the quantity of each product as and when required. Now I am asked to add a select box to add the required units of that product So the selected units of the product need to remain in the session which is not happening.

Here is the showCart() method:
<?php
function showCart() {
global $db;
$cartItems = $_SESSION[‘cartItems’];

if ($cartItems) {


	$output[] = '&lt;form name="scart" action="cart.php?action=update" method="post"&gt;';

	$output[] = '&lt;/tr&gt;';

		foreach ($cartItems as $id=&gt;$qty)
		{

			$cartItems[$id]=$qty;

			$sql = "SELECT * FROM sb_products WHERE id = '$id'";

			$result = $db-&gt;query($sql);
			$row = $result-&gt;fetch();
			extract($row);

			$output[] = '&lt;tr&gt;';
			$output[] = '&lt;td&gt;&lt;a href="cart.php?action=delete&id='.$id.'" class="remove"&gt;Remove&lt;/a&gt;&lt;/td&gt;';
			$output[] = '&lt;td&gt;'.$grade.'&lt;/td&gt;';
			$output[] = '&lt;td&gt;'.$origin.'&lt;/td&gt;';
			echo "&lt;br /&gt;";
			$output[] = '&lt;td&gt;&lt;input id="quan" type="text" name="qty'.$id.'" value="'.$qty.'" size="5" maxlength="5" /&gt;&lt;/td&gt;';

			$string = explode(",",$units);

			$total_count=count($string);

			$output[] ='&lt;td&gt; &lt;select name="punit'.$id.'" class="indexselect"&gt;
			&lt;option value=""&gt;--- Select ---&lt;/option&gt;
			&lt;option value="Pieces" &lt;?php if($sel=="abc"){ echo "selected"; } ?&gt;abc&lt;/option&gt;
			&lt;option value="Tons" &lt;?php if($sel=="xyz"){ echo "selected"; } ?&gt;xyz&lt;/option&gt;
			&lt;/select&gt;&lt;/td&gt;';
		} // for ends


$output[] = '&lt;div style="padding:10px 0 0 0;"&gt;&lt;input type="submit" value="Update product"&gt;&lt;/div&gt;';
$output[] = '&lt;/form&gt;';
$output[] = '&lt;/table&gt;';

}
else {
$output[] = '&lt;p&gt;Your cart is empty.&lt;/p&gt;';
}

return join('',$output);
mysql_free_result();

}
?>

And here are the cart methods:

<?php
$cartItems = $_SESSION[‘cartItems’];
$action = $_GET[‘action’];
$chk = $_GET[‘id’];
$cbox = explode(‘,’,$chk);
$sd=$_POST[“punit”.$id];
$q=$_POST[“qty”.$id];
echo “<br />”;
$string1 = implode($sd,“,”);
$cselect = explode(‘,’,$string1);
$tcount= count($cbox);
$ctcount= count($cselect);

for( $r=0;$r<$ctcount; $r++)
{
$sel[$r] = $cselect[$r];
echo $sel[$r]; // gives select value, now I am not able to get the value back in the showCart() method
}

for( $k=0;$k<$tcount; $k++)
{
$to[$k] = $cbox[$k];

switch ($action)
{
case ‘add’:

if(!empty($cartItems))
{
	if(!array_key_exists($to[$k],$cartItems))
	{
		$cartItems[$to[$k]]='1';
	}
}
else
{
	$cartItems[$to[$k]]='1';
}
	break;
case 'delete':

if(!empty($cartItems))
{
	if(array_key_exists($to[$k],$cartItems))
	{
		$cartItems[$to[$k]]='1';
		unset($to[$k],$cartItems[$id]);
	}
}
	break;
case 'update':

foreach ($_POST as $id=>$qty)
{
if(empty($cartItems))
{
if(!array_key_exists($id,$cartItems))
{
//$cartItems[$id]=$qty;
}
}
else
{
$cartItems[$id]=$qty;
}
}
break;

}

} // for ends
?>

I am just not able to get what is going wrong or ho to pass the value in update method back to the showCart method. Please if someone can help me out?

What error/messages do you get?

the update method creates a new row for textbox value and show the updated value there and also it creates a new row again for select box value and shows it in a textbox.

I have got values in update method, now I need to simply get back these values in form, all related to the same id.

Thanks