title: Creating a PHP shopping cart using sessions from an array
body: <p>Ok so i have the following page that will be my shopping cart page, and I am having trouble using sessions to take the values from the product arrays on 1 page and create a functioning cart. I don't clearly understand how to use php session variables in order to maintain persistent information such as a shopping cart. I would like to figure out how create the cart using the $_SESSION['cart'] and how to pass the data into it so that I can display the quantity of each item in the cart and have add/remove functionality. </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  
    &lt;?php include 'header.php';
  
      if(!empty($_SESSION['cart'])){
  
      }
    ?&gt;
  
  
      &lt;title&gt;Football Items&lt;/title&gt;
      &lt;b&gt;&lt;i&gt;&lt;h1&gt;Shopping Cart - Checkout&lt;/h1&gt;&lt;b&gt;&lt;/i&gt;
      &lt;!-- Bootstrap --&gt;
  
     &lt;link rel="stylesheet" href="styles/styles1.css"&gt;
  
  &lt;link rel="stylesheet" href="css/bootstrap.min.css"&gt;
  
    &lt;/head&gt;
  
    &lt;!--NavStart--&gt;
  &lt;nav class="navbar navbar-default"&gt;
    &lt;div class="container-fluid"&gt;
      &lt;div class="navbar-header"&gt;
        &lt;button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="navbar-collapse-1" aria-expanded="false"&gt;
        &lt;/button&gt;
       &lt;b&gt;&lt;a class="navbar-brand" href="index.php"&gt;Home Page&lt;/a&gt;&lt;/b&gt;
      &lt;/div&gt;
  
  
      &lt;div class="collapse navbar-collapse"&gt;
        &lt;ul class="nav navbar-nav"&gt;
          &lt;li class="active"&gt;&lt;a href=""&gt;About Us &lt;span class="sr-only"&gt;(current)&lt;/span&gt;&lt;/a&gt;&lt;/li&gt;
  
  
          &lt;li&gt;&lt;a href="productlist.php"&gt;Football Jerseys&lt;/a&gt;&lt;/li&gt;
          &lt;li class="dropdown"&gt;
  
        &lt;ul class="nav navbar-nav navbar-right"&gt;
          &lt;li&gt;&lt;a href="Application.php"&gt;Checkout&lt;/a&gt;&lt;/li&gt;
          &lt;li class="dropdown"&gt;
  
            &lt;/ul&gt;
          &lt;/li&gt;
        &lt;/ul&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/nav&gt;
  
  
  
    &lt;div id="wrapper"&gt;
    &lt;div id="wrap"&gt;
  
  
    &lt;?php
        if (!empty($_GET['act'])) 
        {
          if ($_GET['act']=='add') {
              $numr = $_GET['itemid'];
              $name = $_GET['itemname'];
              $quantity = 1;
              $price = $_GET['itemprice'];
              $total = $quantity * $price;
          }
        }
    ?&gt;
  
  
  
    &lt;body&gt;
  
  
  
    &lt;table border="3" style="height: 100% width:200% cellpadding="3" cellspacing="3"&gt;
      &lt;tr&gt;
       &lt;th&gt;Item Number&lt;/th&gt;&lt;/p&gt;
        &lt;th&gt;Item Name&lt;/th&gt;
        &lt;th&gt;Price&lt;/th&gt;
        &lt;th&gt; Quantity &lt;/th&gt;
        &lt;th&gt;Total&lt;/th&gt;
      &lt;/tr&gt;
  
  
        &lt;?php
                  echo "&lt;tr&gt;";
                  echo "&lt;th&gt;$numr&lt;/th&gt;";
                  echo "&lt;td&gt;$name&lt;/td&gt;";
                  echo "&lt;td&gt;$price&lt;/td&gt;";
                  echo "&lt;td&gt;$quantity&lt;/td&gt;";
                  echo "&lt;td&gt;$total&lt;/td&gt;";
                  echo "&lt;/tr&gt;";
  
              ?&gt;
  
  
  
  
    &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  
    &lt;/body&gt;
  
       &lt;div class="container"&gt; 
       &lt;button type="button" style= color:black;background-color:white;" class="btn btn-primary active"&gt;
          &lt;a href="form.php"&gt;Checkout now.&lt;/a&gt;&lt;/button&gt;
  
    &lt;/div&gt;
  &lt;/div&gt;
  
  
  &lt;?php include 'footer.php';?&gt;  
  </code></pre>