title: PHP Shopping Cart: How to update product quantity in cart using session variables?
body: <p>I am in the process of creating my first shopping cart project.But got stuck while updating the product quantity.</p>
  
  <p>I want to update the product quantity using a session variable. Can anyone help me with the code and also tell me how to go about it?</p>
  
  <p>Here is the my_cart.php page code</p>
  
  <pre><code>    &lt;tr&gt;
          &lt;th class="tablerow"&gt;Product Code&lt;/th&gt;
          &lt;th class="tablerow"&gt;Product Name&lt;/th&gt;
          &lt;th class="tablerow"&gt;Image&lt;/th&gt;
          &lt;th class="tablerow"&gt;Quantity&lt;/th&gt;
          &lt;th class="tablerow"&gt;Price&lt;/th&gt;
          &lt;th class="tablerow"&gt;Total Price&lt;/th&gt;
          &lt;th class="tablerow"&gt;Action&lt;/th&gt;                 
      &lt;/tr&gt;
  
      &lt;?php
      $grand_total = 0;                                   // For Calculating Grand Price
      foreach($_SESSION['cart'] as $id=&gt;$quantity)
      {
          $sql="SELECT * FROM products WHERE id='$id'";
          $result=mysql_query($sql) or die("Error Message");
          while($row=mysql_fetch_array($result))
          {       
          $grand_total+= $row['product_price']*$quantity; // For Calculating Grand Price  
      ?&gt;        
  
      &lt;tr&gt;                
          &lt;td class="tablerow"&gt;&lt;?php echo $row['id']; ?&gt;&lt;/td&gt;
          &lt;td class="tablerow"&gt;&lt;?php echo $row['product_name']; ?&gt;&lt;/td&gt;
          &lt;td class="tablerow"&gt;&lt;?php echo "&lt;img height='50' width='50' src='admin/".$row['product_image']."'/&gt;" ?&gt;&lt;/td&gt;
  
          &lt;form name="update_cart" action="update_cart.php" method="post"&gt;
  
          &lt;td class="tablerow"&gt;&lt;input type="text" name="quantity" value="&lt;?php echo $quantity; ?&gt;" /&gt;&lt;br /&gt;&lt;input type="image" src="admin/images/updatecart.png" name="Update" value="Update" /&gt;&lt;/td&gt;
  
          &lt;/form&gt;
  
          &lt;td class="tablerow"&gt;&lt;?php echo $row['product_price']; ?&gt;&lt;/td&gt;
          &lt;td class="tablerow"&gt;&lt;?php echo $quantity*$row['product_price']; ?&gt; &lt;/td&gt;
          &lt;td class="tablerow"&gt;&lt;?php print "&lt;a href='delete_cart.php?pid=".$row['id']."'&gt;&lt;img src='admin/images/delete.png'&gt;&lt;/a&gt;"; ?&gt;&lt;/td&gt;&lt;/form&gt;
      &lt;/tr&gt;
  
      &lt;?php 
          }
      }
      ?&gt;
  
      &lt;tr&gt;
          &lt;td class="tablerow" colspan="7"&gt;Grand Total: Rs &lt;?php echo $grand_total; ?&gt;&lt;/td&gt;
      &lt;/tr&gt;       
  
      &lt;tr&gt;
          &lt;td class="tablerow" colspan="7"&gt;&lt;?php print "&lt;a href='clear_cart.php'&gt;&lt;img src='admin/images/clearcart.png'&gt;&lt;/a&gt;&lt;a href='http://localhost/Shopping-Cart/front-end/'&gt;&lt;img src='admin/images/continueshopping.png'&gt;&lt;/a&gt;&lt;a href='update_cart.php'&gt;&lt;img src='admin/images/placeorder.png'&gt;&lt;/a&gt;";?&gt;&lt;/td&gt;
      &lt;/tr&gt;              
  
      &lt;/table&gt;
  </code></pre>