PHP & Javascript Shopping Cart - I can't code good. :(

I’m struggling with my attempts to make a shopping cart and use Javascript along with PHP.
The main problem I’m having with this code is the color field, and it not updating correctly.
Any help at all would be appreciated.

[php]<?
include(“includes/db.php”);
include(“includes/functions.php”);

if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
	remove_product($_REQUEST['pid']);
}
else if($_REQUEST['command']=='clear'){
	unset($_SESSION['cart']);
	$_SESSION['qty'] = 0;
}
else if($_REQUEST['command']=='update'){
	$max=count($_SESSION['cart']);
	for($i=0;$i<$max;$i++){
		$pid=$_SESSION['cart'][$i]['productid'];
		$q=intval($_REQUEST['product'.$pid]);
		$color=strval($_REQUEST['color'.$pid]);
		if($q>0 && $q<=400){
			$_SESSION['cart'][$i]['qty']=$q;
			$_SESSION['cart'][$i]['color']=$color;
		}
		else{
			$msg='Some proudcts not updated, quantity must be a number between 1 and 400.';
		}
	}
}

$ks = 0;
?>
//doctype

//more head code

//formatting HTML

Your Shopping Cart

<?=$msg?>
<? if(is_array($_SESSION['cart'])){ echo ''; $max=count($_SESSION['cart']); for($i=0;$i<$max;$i++){ $pid=$_SESSION['cart'][$i]['productid']; $q=$_SESSION['cart'][$i]['qty']; $color=$_SESSION['cart'][$i]['color']; $pname=get_product_name($pid); $sku=get_sku($pid); if($q==0) continue;
				mysql_connect ('localhost', '******', '******') ;
				mysql_select_db ('********');

				$sql1 = "SELECT * FROM items WHERE sku='$sku' ";

				$result1 = mysql_query($sql1) or print ("Can't select entries from table.<br />" . $sql1 . mysql_error());

				while($row1 = mysql_fetch_array($result1)) {

					$color1  = stripslashes($row1['color1']);
					$color2  = stripslashes($row1['color2']);
					$color3  = stripslashes($row1['color3']);
					$color4  = stripslashes($row1['color4']);
				
		?>
        		<tr bgcolor="#FFFFFF">
                <td class="cart" width="250px"><?=$pname?></td>
                <td class="cart" width="100px">$ <?=get_price($pid)?></td>
                <td class="cart" width="60px"><input type="text" name="product<?=$pid?>" value="<?=$q?>" maxlength="3" size="2" style="width: 40px;" /></td>               
                <td class="cart" width="100px">$ <?=get_price($pid)*$q?></td>
                <td class="cart" width="100px">
                <select name="color<?=$pid?>">
                <option value="#"><?php echo $color; ?></option>
                <option value="shoppingcart.php?color=<?=$color1?>"><?=$color1?></option>
                <option value="shoppingcart.php?color=<?=$color2?>"><?=$color2?></option>
                <option value="shoppingcart.php?color=<?=$color3?>"><?=$color3?></option>
                <option value="shoppingcart.php?color=<?=$color4?>"><?=$color4?></option>
              </select>
              </td>
                <td class="cart" width="60px" align="center">
                <a href="javascript:del(<?=$pid?>)">
                <img src="delete.png" width="30px" height="30px" border="0" alt="remove item" />
                </a>
                </td>
                </tr>
        <?	
				}
			}
		?>
			<tr><td><b style="margin-left: 5px;">Order Total: $<?=get_order_total()?></b><br /><b style="margin-left: 5px;">Total Weight: <?=get_order_total_weight()?>  ounces.</b></td> <td colspan="5" align="right"><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"><input type="button" value="Place Order" onclick="window.location='direct_post.php'"></td></tr>
		<?  }else{
			
			echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
			
		}
	?>
    </table>
</div>
// more formatting [/php]
Name Price Qty Amount Options Delete
Sponsor our Newsletter | Privacy Policy | Terms of Service