title: id is not defined in my shopping cart
body: <p>I was doing a shopping cart tutorial,</p>
  
  <p>I met with one error stating that my item_id is not  defined
  for <code>$cartOutput .= "Item ID: " . $each_item['item_id']."&lt;br&gt;";</code>
  However,
  I have defined the item_id.</p>
  
  <p>here is my code.
  Can someone tell me what's wrong?</p>
  
  <pre><code>&lt;?php
  //script error reporting
  error_reporting(E_ALL);
  ini_set('display_errors','1');
  ?&gt;
  &lt;?php
  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["supermarketcart"]) || count($_SESSION["supermarketcart"]) &lt; 1) { 
          // RUN IF THE CART IS EMPTY OR NOT SET
          $_SESSION["supermarketcart"][] = array(1 =&gt; array("item_id" =&gt; $pid, "quantity" =&gt; 1));
  
      } else {
          // RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
          foreach ($_SESSION["supermarketcart"] as $each_item) { 
                $i++;
                while (list($key, $value) = each($each_item)) {
                    if ($key == "item_id" &amp;&amp; $value == $pid) {
                        // That item is in cart already so let's adjust its quantity using array_splice()
                        array_splice($_SESSION["supermarketcart"], $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["supermarketcart"], array("item_id" =&gt; $pid, "quantity" =&gt; 1));
             }
      }
      header("location: cart.php"); 
      exit();
  }
  ?&gt;
  &lt;?php
  //if user choose to empty cart
  if(isset($_GET['cmd']) &amp;&amp; $_GET['cmd'] == "emptycart")
  {
      unset($_SESSION["supermarketcart"]);
  }
  ?&gt;
  
  &lt;?php
  //render the cart for user to view
  $cartOutput = "";
  if(!isset($_SESSION["supermarketcart"]) || count($_SESSION["supermarketcart"]) &lt; 1 ){
      $cartOutput .= "&lt;h2 align = 'center'&gt; Your shopping cart is empty&lt;/h2&gt;";
  }
  else
  {
      $i = 0;
      foreach ($_SESSION["supermarketcart"] as $each_item)
      {
          $i++;
  
      $item_id = $each_item['item_id'];
  
          $sql = mysql_query("SELECT * FROM supermarket WHERE id = '$item_id' LIMIT 1");
          while($row = mysql_fetch_array($sql)){
              $product_des = $row_supermarketDetails['description'];
      $price = $row_supermarketDetails['price'];
  
      }
          $cartOutput .= "&lt;h2&gt;Cart Item $i&lt;/h2&gt;";
          $cartOutput .= "Item ID: " . $each_item['item_id']."&lt;br&gt;";
          $cartOutput .= "Item Quatity: " . $each_item['quantity']."&lt;br&gt;";
          $cartOutput .= "Item Name: " . $product_des."&lt;br&gt;";
  
          $cartOutput .= "Item Price: " . $price."&lt;br&gt;";
  
  
  
      }
  }
  
  ?&gt;
  </code></pre>