title: Submit button not adding items to shopping cart in my PHP page
body: <p>I'm trying to follow a simple add to cart tutorial using php, sql, with my database on phpmyadmin, but when the user clicks "add to cart", nothing is displayed in the shopping cart table. </p>
  
  <p>Any non-php solutions are welcome.
  Here is the tutorial: <a href="http://www.webslesson.info/2016/08/simple-php-mysql-shopping-cart.html" rel="nofollow noreferrer">http://www.webslesson.info/2016/08/simple-php-mysql-shopping-cart.html</a></p>
  
  <p>Thank you!</p>
  
  <pre><code>&lt;?php
  session_start();
  require_once ('database_conn.php');
  if (isset($_POST["add_to_cart"])) {
      if (isset($_SESSION["shopping_cart"])) {
          $item_array_id = array_column($_SESSION["shopping_cart"], "productID");
          if (!in_array($_GET["id"], $item_array_id)) {
              $count = count($_SESSION["shopping_cart"]);
              $item_array = array(
                  'productID' =&gt; $_GET["productID"],
                  'productName' =&gt; $_POST["productName"],
                  'productPrice' =&gt; $_POST["productPrice"],
                  'productAisle' =&gt; $_POST["productAisle"]
              );
              $_SESSION["shopping_cart"][$count] = $item_array;
          }
      } else {
          $item_array = array(
              'productID' =&gt; $_GET["productID"],
              'productName' =&gt; $_POST["productName"],
              'productPrice' =&gt; $_POST["productPrice"],
              'productAisle' =&gt; $_POST["productAisle"]
          );
          $_SESSION["shopping_cart"][0] = $item_array;
      }
  }
  if (isset($_GET["action"])) {
      if ($_GET["action"] == "delete") {
          foreach ($_SESSION["shopping_cart"] as $keys =&gt; $values) {
              if ($values["item_id"] == $_GET["id"]) {
                  unset($_SESSION["shopping_cart"][$keys]);
                  echo '&lt;script&gt;alert("Item Removed")&lt;/script&gt;';
                  echo '&lt;script&gt;window.location="add.php"&lt;/script&gt;';
              }
          }
      }
  }
  ?&gt;
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
      &lt;head&gt;
          &lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"&gt;&lt;/script&gt;
          &lt;link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" /&gt;
          &lt;script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"&gt;&lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
          &lt;br /&gt;
          &lt;div class="container" style="width:700px;"&gt;
              &lt;?php
              $name = isset($_REQUEST['name']) ? $_REQUEST['name'] : null;
              $sqlProducts = "SELECT productID, productName, productPrice, productImage, productAisle
  
                      FROM s_products WHERE productName LIKE '%$name%'";
              $rProducts = mysqli_query($conn, $sqlProducts) or die(mysqli_error($conn));
  
              while ($row = mysqli_fetch_assoc($rProducts)) {
                  $productID = $row['productID'];
                  $productName = $row['productName'];
                  $productImage = $row['productImage'];
                  $productAisle = $row['productAisle'];
                  {
                      ?&gt;
                      &lt;div class="col-md-4"&gt;
                          &lt;form method="post" action="add.php?action=add&amp;id=&lt;?php echo $row["id"]; ?&gt;"&gt;
                              &lt;div style="border:1px solid #333; background-color:#f1f1f1; border-radius:5px; padding:16px;" align="center"&gt;
                                  &lt;img src="&lt;?php echo $row["productImage"]; ?&gt;" class="img-responsive" /&gt;&lt;br /&gt;
                                  &lt;h4 class="text-info"&gt;&lt;?php echo $row["productName"]; ?&gt;&lt;/h4&gt;
                                  &lt;h4 class="text-danger"&gt;$ &lt;?php echo $row["productPrice"]; ?&gt;&lt;/h4&gt;
                                  &lt;input type="text" name="quantity" class="form-control" value="1" /&gt;
                                  &lt;input type="hidden" name="hidden_name" value="&lt;?php echo $row["productName"]; ?&gt;" /&gt;
                                  &lt;input type="hidden" name="hidden_price" value="&lt;?php echo $row["productPrice"]; ?&gt;" /&gt;
                                  &lt;input type="submit" name="add_to_cart" style="margin-top:5px;" class="btn btn-success" value="Add to Cart" /&gt;
                              &lt;/div&gt;
                          &lt;/form&gt;
                      &lt;/div&gt;
                      &lt;?php
                  }
              }
              ?&gt;
              &lt;div style="clear:both"&gt;&lt;/div&gt;
              &lt;br /&gt;
              &lt;h3&gt;Order Details&lt;/h3&gt;
              &lt;div class="table-responsive"&gt;
                  &lt;table class="table table-bordered"&gt;
                      &lt;tr&gt;
                          &lt;th width="40%"&gt;Item Name&lt;/th&gt;
                          &lt;th width="10%"&gt;Quantity&lt;/th&gt;
                          &lt;th width="20%"&gt;Price&lt;/th&gt;
                          &lt;th width="15%"&gt;Total&lt;/th&gt;
                          &lt;th width="5%"&gt;Action&lt;/th&gt;
                      &lt;/tr&gt;
                      &lt;?php
                      if (!empty($_SESSION["shopping_cart"])) {
                          $total = 0;
                          foreach ($_SESSION["shopping_cart"] as $keys =&gt; $values) {
                              ?&gt;
                              &lt;tr&gt;
                                  &lt;td&gt;&lt;?php echo "$productName"; ?&gt;&lt;/td&gt;
                                  &lt;td&gt;&lt;?php echo "$productPrice"; ?&gt;&lt;/td&gt;
                                  &lt;td&gt;$ &lt;?php echo "$productAisle"; ?&gt;&lt;/td&gt;
  
                                  &lt;td&gt;&lt;a href="add.php?action=delete&amp;id=&lt;?php echo "$productID";
                          }
                          ?&gt;"&gt;&lt;span class="text-danger"&gt;Remove&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
                          &lt;/tr&gt;
  
                          &lt;tr&gt;
                              &lt;td colspan="3" align="right"&gt;Total&lt;/td&gt;
                              &lt;td align="right"&gt;$ &lt;?php echo number_format($total, 2); ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;?php
                      }
                      ?&gt;
                  &lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;br /&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>