title: shopping cart in php Not showing Product Details
body: <p>I am new to PHP and i am making a shopping cart for my website.  The problem is when i click on the button "ADD TO SHOPPING CART" It goes to the cart.php page where i am trying to display the product name, details, price, quantity to adjust , total price, remove the item but it is not display all the details about the product it only shows me the quantity. Here is my code to display the cart product.</p>
  
  <pre><code>$cartOutput="";
  $cartTotal="";
  if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &lt; 1) 
  {
      $cartOutput = "&lt;h2 align='center'&gt;Your shopping cart is empty&lt;/h2&gt;";
  } 
  else 
  {
      $i=0;
      foreach($_SESSION["cart_array"] as $each_item) 
          {
          $i++;
              $item_id = $each_item['item_id'];
          $result = mysqli_query($con, "SELECT * FROM products WHERE id='$item_id' LIMIT 1 ");
          if($result == FALSE) {
              die(mysql_error()); // TODO: better error handling
      }
      while($row = mysqli_fetch_array($result)) 
          {
              $id = $row["id"];
              $product_name = $row["product_name"];
              $price = $row["price"];
              $details = $row["details"];
          }
          $pricetotal = $price * $each_item['quantity'];
          $cartTotal = $pricetotal + $cartTotal;
          // Dynamic Table row assembly
          $cartOutput .= '&lt;tr&gt;';
          $cartOutput .= '&lt;td align=\'center\' &gt;' . $product_name . '&lt;br/&gt;&lt;/td&gt;';
          $cartOutput .= '&lt;td align=\'center\' &gt;' . $details . '&lt;/td&gt;';
          $cartOutput .= '&lt;td align=\'center\' &gt;' . $price . '&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt;
              &lt;form action="cart.php" method="post"&gt;
              &lt;input name="quantity" type="text" value="' . $each_item['quantity'] . '" size="1" maxlength="2" /&gt;
              &lt;input name="adjustBtn' . $item_id . '" type="submit" value="change" /&gt;
              &lt;input name="item_to_adjust" type="hidden" value="' . $item_id . '" /&gt;
              &lt;/form&gt;
              &lt;/td&gt;';
          //$cartOutput .= '&lt;td align=\'center\' &gt;' . $each_item['quantity'] . '&lt;/td&gt;';
          $cartOutput .= '&lt;td align=\'center\' &gt;' . $pricetotal . '&lt;/td&gt;';
          $cartOutput .= '&lt;td&gt; &lt;form action="cart.php" method="post"&gt;
              &lt;input name="deleteBtn' . $item_id . '" type="submit" value="X" /&gt; 
              &lt;input name="index_to_remove" type="hidden" value="' . $i . '" /&gt;&lt;/form&gt; &lt;/td&gt;';
          $cartOutput .= '&lt;/tr&gt;';
      $i++;
  
      }
  
  }
  </code></pre>
  
  <p>(if user attempts to add something to the cart from the product page)</p>
  
  <pre><code>if (isset($_POST['pid'])) {
      $pid = $_POST['pid'];
      $wasFound = false;
      $i = 0;
  
      // If the cart session variable is not set or cart array is empty
      if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) &lt; 1) { 
      // RUN IF THE CART IS EMPTY OR NOT SET
      $_SESSION["cart_array"] = array(0 =&gt; array("item_id" =&gt; $pid, "quantity"=&gt; 1));
  } else {
      // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
      foreach ($_SESSION["cart_array"] as $each_item) { 
          $i++;
          while (list($key, $value) = each($each_item)) {
  
              if ($key == "item_id" &amp;&amp; $value == $pid) {
  
              array_splice($_SESSION["cart_array"], $i-1, 1, 
              array(array("item_id" =&gt; $pid, "quantity" =&gt; $each_item['quantity'] + 1)));
              $wasFound = true;
              } // close if condition
          } // close while loop
      } // close foreach loop
  
      if ($wasFound == false) {
          array_push($_SESSION["cart_array"], array("item_id" =&gt; $pid, "quantity" =&gt; 1));
      }
  }
  
  header("location: cart.php"); 
  exit();
  }
  </code></pre>
  
  <p>to show the product </p>
  
  <pre><code>$dynamicList = "";
  
  $result = mysqli_query($con,"SELECT * FROM products ");
  $productCount = mysqli_num_rows($result); // count the output amount
  
  
  
  
  if ($productCount &gt; 0) {
  while($row = mysqli_fetch_array($result)){ 
                   $id = $row["id"];
           $product_name = $row["product_name"];
           $product_code = $row["product_code"];
           $availability = $row["availability"];
           $price = $row["price"];
           $category = $row["category"];
           $subcategory = $row["subcategory"];
           $details = $row["details"];
           $date_added = strftime("%b %d, %Y",   
  strtotime($row["date_added"]));
           // To show latest items on the home page
  
           $dynamicList .= ' &lt;div class="product-items"&gt;
    &lt;div class="product-block"&gt;
    &lt;div class="product-block-inner"&gt;
  
                  &lt;div class="image"&gt;
                      &lt;a href="product.php?id=' . $id . '"&gt;&lt;img 
   src="product_images/' . $id . '.jpg" /&gt; &lt;/a&gt;
                  &lt;/div&gt;
  
                  &lt;div class="name"&gt;
                      &lt;a href="product.php?id=' . $id . '"&gt;' . 
   $product_name . '&lt;/a&gt;
                  &lt;/div&gt;
                  &lt;div class="price"&gt;
                      RS. ' . $price . '
                      &lt;br /&gt;
                      Availability: ' . $availability . '
                  &lt;/div&gt;
                  &lt;div class="cart"&gt;
                      &lt;form id="form1" name="form1" 
  method="post" action="cart.php"&gt;
                          &lt;input type="input" name="pid" id="pid" 
  value="&lt;?php echo $id; ?&gt;" /&gt;
                          &lt;input type="submit" name="button" 
  id="button" class="button" value="Add to Shopping Cart" /&gt;
                          &lt;/form&gt;
  
                  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  
  
  
  
  
  
                          '; 
  
  
  }
  } else {
  $dynamicList = "We have no products listed in our store yet";
  
  }
  </code></pre>