title: Simple PHP Shopping Cart Quantity
body: <p>I am a rookie in PHP and I'm trying to make a shopping website for a college module.</p>
  
  <p>Here is my products page that lists all of the products:</p>
  
  <pre><code>//Get the category from the URL
  $category = $_GET['category'];
  
  echo("&lt;h1&gt;Products: $category&lt;/h1&gt;");
  echo("&lt;FORM METHOD='LINK' ACTION='products.php'&gt;");
  echo("&lt;INPUT TYPE='submit' VALUE='Back'&gt;");
  echo("&lt;/FORM&gt;");
  echo("&lt;hr&gt;");
  
  //Include database file with settings im
  require "db.inc";
  
  //Store the connection in a variable for later use
  $connection = mysql_connect($hostname, $username, $password);
  
  //Check for connection
  if(! $connection )
  {
    die('Could not connect: ' . mysql_error());
  }
  
  //If the category is all then
  if($category == "All")
  {
      $query = "SELECT * FROM products";//Select everything
  }
  //If it's not then..
  else
  {
      $query = "SELECT * FROM products WHERE category = '$category'";
  }
  
  //Open the Database
  mysql_select_db($dbname);
  
  //Start the query
  $result = mysql_query($query, $connection);
  
  if(!$result )
  {
    die('Could not retrieve data: ' . mysql_error());
  }
  
  //Loop through the rows and display each object
  while($row = mysql_fetch_array($result))
  {
      //Define all variables we will use
      $productid = $row['id'];
      $productname = $row['name'];
      $productdescription = $row['description'];
      $productimage = $row['image'];
      $productprice = $row['price'];
      $productstock = $row['stock'];
  
      //Display each product and it's info
      echo("&lt;h3&gt;$productname&lt;/h3&gt;");
      echo("&lt;a href=$productimage&gt;&lt;img border='0' alt=$productname src=$productimage width='100' height='100'&gt;&lt;/a&gt;&lt;br&gt;");
      echo("$productdescription&lt;br&gt;");
      echo("&lt;b&gt;Price:&lt;/b&gt; £$productprice (ex VAT)&lt;br&gt;");
      echo("&lt;b&gt;Stock:&lt;/b&gt; $productstock&lt;br&gt;");
  
      //Create a link for each product, that goes to the add to cart script with the product id in the URL
      //Only if youre logged in can you see this button
      if( isset($_SESSION['login']))
      {
  
          echo("&lt;FORM METHOD='POST' ACTION='process_addtocart.php?id=$productid&amp;quantity=1'&gt;");
          echo("&lt;INPUT TYPE='submit' VALUE='Add to Cart'&gt;");
          echo("&lt;/FORM&gt;");
      }
      echo("&lt;hr&gt;");
  }
  </code></pre>
  
  <p>As you can see it gets all the products from the db and adds a button that links to the addcart php file with the id and quantity to add.</p>
  
  <p>Here is my add to cart function:</p>
  
  <pre><code>&lt;?php
      //Make sure user is logged in first
      if( isset($_SESSION['login']))
      {
  
          //Setup our shopping cart if it isnt already setup into an array table to hold item info
          if( empty($_SESSION['shoppingcart']))
          {
              $_SESSION['shoppingcart'] = array();
  
          }
  
          $id = $_GET['id'];
          $quantitytoadd = $_GET['quantity'];
  
          if( isset( $_SESSION['shoppingcart'][$id]))
          {
              //CODE TO ADD TO QUANTITY????
  
          }
  
          array_push($_SESSION['shoppingcart'], $id);
          echo("Item has been added to your cart!");
  
  
      }
      else
      {
          echo("&lt;p&gt;Please login to add items to your shopping cart!&lt;/P&gt;");
      }
  
  ?&gt;
  </code></pre>
  
  <p>How would I make it increment a quantity value for THAT specific ID in the array table each time? </p>
  
  <p>Would it be something like:</p>
  
  <pre><code>array_push($_SESSION['shoppingcart'], $id, $quantitytoadd++);
  </code></pre>