title: creating a shopping cart and updating the values in it using php
body: <p>I am creating a shopping cart which has four buttons continue shopping, clear cart, update cart and place order I am facing a problem with the sessions like when I press the update cart button it empties my cart rater then updating it any one help in showing me that where i am doing it rong
  here is my code</p>
  
  <pre><code>&lt;?php
      include("includes/db.php");
      include("includes/functions.php");
  
      if(isset($_REQUEST['command'])=='delete' &amp;&amp; $_REQUEST['pid']&gt;0){
          remove_product($_REQUEST['pid']);
      }
      elseif(isset($_REQUEST['command'])=='clear'){
          $_SESSION["cart"] = array();
      }
      elseif($_REQUEST['command']=='update'){
          $max=count($_SESSION['cart']);
          for($i=0;$i&lt;$max;$i++){
              $pid=$_SESSION['cart'][$i]['productid'];
              $q=intval($_REQUEST['product'.$pid]);
              if($q&gt;0 &amp;&amp; $q&lt;=999){
                  $_SESSION['cart'][$i]['qty']=$q;
  
              }
              else{
                  $msg='Some proudcts not updated!, quantity must be a number between 1 and 999';
              }
          }
      }
  
  ?&gt;
  </code></pre>
  
  <p>here is my javascript</p>
  
  <pre><code>function update_cart(){
      document.form1.command.value='update';
      document.form1.submit();
  }
  </code></pre>
  
  <p>here is my code</p>
  
  <pre><code>&lt;?php
              if(is_array($_SESSION['cart'])){
                  echo '&lt;tr bgcolor="#FFFFFF" style="font-weight:bold"&gt;&lt;td&gt;Serial&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Price&lt;/td&gt;&lt;td&gt;Qty&lt;/td&gt;&lt;td&gt;Amount&lt;/td&gt;&lt;td&gt;Options&lt;/td&gt;&lt;/tr&gt;';
                  $max=count($_SESSION['cart']);
                  for($i=0;$i&lt;$max;$i++){
                      $pid=$_SESSION['cart'][$i]['productid'];
                      $q=$_SESSION['cart'][$i]['qty'];
                      $pname=get_product_name($pid);
                      if($q==0) continue;
              ?&gt;
                      &lt;tr bgcolor="#FFFFFF"&gt;&lt;td&gt;&lt;?php echo $i+1?&gt;&lt;/td&gt;&lt;td&gt;&lt;?php echo $pname?&gt;&lt;/td&gt;
                      &lt;td&gt;$ &lt;?php echo get_price($pid)?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;input type="text" name="product&lt;?php echo $pid?&gt;" value="&lt;?php echo $q?&gt;" maxlength="3" size="2" /&gt;&lt;/td&gt;                    
                      &lt;td&gt;$ &lt;?php echo get_price($pid)*$q?&gt;&lt;/td&gt;
                      &lt;td&gt;&lt;a href="javascript:del(&lt;?php echo $pid?&gt;)"&gt;Remove&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;?php                   
                  }
              ?&gt;
                  &lt;tr&gt;&lt;td&gt;&lt;b&gt;Order Total: $&lt;?php echo get_order_total()?&gt;&lt;/b&gt;&lt;/td&gt;&lt;td colspan="5" align="right"&gt;&lt;input type="button" value="Clear Cart" onclick="clear_cart()"&gt;&lt;input type="button" value="Update Cart" onclick="update_cart()"&gt;&lt;input type="button" value="Place Order" onclick="window.location='billing.php'"&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;?php
              }
              else{
                  echo "&lt;tr bgColor='#FFFFFF'&gt;&lt;td&gt;There are no items in your shopping cart!&lt;/td&gt;";
              }
          ?&gt;
  </code></pre>