title: Updating Session Variable for a shopping cart
body: <p>I'm new to php (have only been playing around with it for a couple of months) and I am building a friend a really simple e-commerce website for which I am building an equally simple shopping cart.  </p>
  
  <p>Here's the basic idea of the cart:  Currently, the user browses the products page (based off of productID), selects a color for an item (which selects ProdOptID, which is unique to every single item), and then submits that information to $_SESSION['Cart'] via posting through a form.  That information is then used to access a mysql DB to pull out all the rest of the product information, which then gets displayed in a mini-cart.  Up to that point, it works fine.  It is only when I try to create a review/edit page where I get tripped up.  For some reason, I can only update the last one.  Anyone got any ideas or spot any problems?</p>
  
  <p>The code for the review/edit page:</p>
  
  <pre><code>&lt;div class="ReviewCheckout_Main"&gt;
  &lt;h1 class="ReviewCheckout_Title"&gt;Review Your Cart&lt;/h1&gt;
  &lt;div class="ReviewCheckout_Form"&gt;
      &lt;form action="/BeautifulUrns/includes/ReviewCheckout_Processing.php" method="post"&gt;
          &lt;?php
              if (isset($_SESSION['Cart'])) {
                  foreach ($_SESSION['Cart'] as $ID =&gt; $QTY){
                      $Query = "SELECT *
                          FROM ProductsOptions
                          LEFT OUTER JOIN Products
                          ON ProductsOptions.ProductID=Products.ProductID
                          WHERE ProdOptID = $ID";
                      $Result = mysql_query($Query, $Connection);
                      $Row = mysql_fetch_array($Result);
  
                      echo "&lt;input type='text' name='Edit_Qty' value=" . $QTY . " /&gt;";
                      echo "&lt;b&gt;" . $Row['ProductName'] . "&lt;/b&gt; ";
                      echo "&lt;b&gt; - " . $Row['POName'] . "&lt;/b&gt; ";
                      echo "&lt;input type='hidden' name='Edit_ID' value='{$Row['ProductID']}' /&gt;";
                      echo "&lt;input type='hidden' name='Edit_ProdOptID' value='{$Row['ProdOptID']}' /&gt;";
                      echo "&lt;br /&gt;";
                  }
              }
          ?&gt;
  
          &lt;input type="submit" /&gt;
      &lt;/form&gt;
      &lt;a href="/BeautifulUrns/index.php"&gt;Return Home&lt;/a&gt;
  &lt;/div&gt;    
  </code></pre>
  
  <p>    </p>
  
  <p>The Code for the processing page:</p>
  
  <pre><code>&lt;?php session_start();
  $ID = mysql_real_escape_string((int)$_POST['Edit_ProdOptID']); // GRABS PRODOPT ID
  $PRODUCTID = mysql_real_escape_string((int)$_POST['Edit_ID']);  //GRABS PRODUCT ID
  $QTY = mysql_real_escape_string((int)$_POST['Edit_Qty']); // GRABS QUANTITY            
  
  if(isset($ID)) {
     if (isset($QTY) &amp;&amp; $QTY &gt; 0){
      if (isset($_SESSION['Cart'])) {
          $_SESSION['Cart'][$ID] = $QTY;
      }
      else {
          $_SESSION['Cart'] = NULL;
          $_SESSION['Cart'][$ID] = $QTY;
          }
      }
  }
  ?&gt;
  </code></pre>