title: Adding quantity to basket item is adding a new item
body: <p>I am creating a basket and what I want is if an item that is already in the basket is added again, the quantity of the original item will be appended by 1.</p>
  
  <p>Instead when I add an item that is already in the basket, a new item is added, and the quantity of this new item can be appended by clicking +1 on the original item.</p>
  
  <p><strong>basket.php</strong></p>
  
  <pre><code>&lt;?php
    foreach ($_SESSION["basket"] as $basketItemArray) {                   
  ?&gt;
  
  &lt;form role="form" action="includes/functions/create_shopping_cart.php" method="post"&gt;
      &lt;button type="submit" name="basket-button" class="btn btn-default" value="&lt;?php echo $basketItemArray["item_id"]; ?&gt;"&gt;&lt;i class="fa fa-plus" aria-hidden="true"&gt;&lt;/i&gt;&lt;/button&gt;
      &lt;? echo $basketItemArray["quantity"]; ?&gt;
      &lt;button class="btn btn-default"&gt;&lt;i class="fa fa-minus" aria-hidden="true"&gt;&lt;/i&gt;&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>The above form sends the <strong><em>item_id</em></strong> through the value of the + button.</p>
  
  <p><strong>create_shopping_cart.php</strong></p>
  
  <pre><code>$product_id = $_POST['basket-button'];
  $sql = "SELECT * FROM menu WHERE product_id='".$product_id."'";
  
  $result = $connection-&gt;query($sql);
  $row = $result-&gt;fetch_assoc();
  
  if (empty($_SESSION["basket"])) {
      $_SESSION["basket"]  = array( 
  
      array( "item_id"=&gt;$row['product_id'], "item_name"=&gt;$row['name'],"quantity"=&gt;1 , "price"=&gt;$row['price']) );
  
  } else {
      // There is already a basket to append to
      $current_basket = $_SESSION["basket"];
  
      $found = false;
      foreach($_SESSION['basket'] as $product)
      {
          if($product_id == $product['item_id']) {
              $found = true;
              break;
          }
      }
  
      if($found)
      {
          $_SESSION['basket'][$product_id]['quantity'] ++;               
      } else {
          $new_basket  = array( 
  
          array( "item_id"=&gt;$row['product_id'], "item_name"=&gt;$row['name'],"quantity"=&gt;1 , "price"=&gt;$row['price']) );
  
          $_SESSION['basket'] = array_merge($current_basket, $new_basket);      
      } 
  }
  </code></pre>
  
  <p><strong>Result</strong>
  <a href="https://i.stack.imgur.com/nPbTB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nPbTB.png" alt="This is what the result of clicking the + button on the original item twice"></a></p>