title: How send all cart items by using form and insert into the database table
body: <p>I have some problems while placing order in my php shopping cart website. I added cart items successfully but when i placing order the all cart items need to insert my database order table. I am using form to post all values from cart and insert into database. There is last updated cart item only inserted my database. The remaining items did not insert into my database. Anybody please help me. Thanks in advance.</p>
  
  <p>My code is</p>
  
  <pre><code>foreach ($_SESSION["cart_array"] as $each_item) {
  
      $item_id = $each_item['item_id'];
      $sql = mysql_query("SELECT * from products WHERE pid='$item_id' LIMIT 1");
      while ($row = mysql_fetch_array($sql)) {
          $product_name = $row["pname"];
          $price = $row["price"];
          $details = $row["description"];
          $image = '&lt;img style="border:#666 1px solid;" src = "admin123/products/' . $item_id . '.jpg" alt="' . $product_name. '" width="50" height="50" border="1" /&gt;';
      }
      $pricetotal = $price * $each_item['quantity'];
      $cartTotal = $pricetotal + $cartTotal;
  
      $cartOutput .='  &lt;form action="cart.php" method="post"&gt;
      &lt;div class="col-lg-2 col-md-2 col-sm-2 pm-cart-info-column"&gt;'.$image.'
                          &lt;/div&gt;
                          &lt;div class="col-lg-2 col-md-2 col-sm-2 pm-cart-info-column text"&gt;
                              &lt;a href="store.php?pid='.$item_id.'"&gt;'.$product_name.'&lt;/a&gt;
                          &lt;/div&gt;
  
                          &lt;div class="col-lg-2 col-md-2 col-sm-2 pm-cart-info-column text"&gt;
                              &lt;p&gt;Price: '.$price.'&amp;nbsp;€&amp;nbsp;&lt;/p&gt;
                          &lt;/div&gt;
  
                          &lt;div class="col-lg-2 col-md-2 col-sm-2 pm-cart-info-column quantity"&gt;
                              &lt;div class="quantity buttons_added pm-checkout-quantity"&gt;
                                    &lt;input type="number" size="4" class="input-text qty cart text" title="Qty" value="' . $each_item['quantity'] . '" name="quantity" min="1" step="1" &gt;                    
                              &lt;/div&gt;&lt;!-- quantity buttons end --&gt;
                          &lt;/div&gt;
  
                          &lt;div class="col-lg-2 col-md-2 col-sm-2 pm-cart-info-column text"&gt;
                              &lt;p&gt;Sub-Total: '.$pricetotal.'&amp;nbsp;€&amp;nbsp;&lt;/p&gt;
                          &lt;/div&gt;
  
                          &lt;div class="col-lg-2 col-md-2 col-sm-2 pm-cart-info-column"&gt;
                              &lt;a href="cart.php?index_to_remove='.$i.'" class="pm-rounded-btn pm-primary pm-cart-remove"&gt;Remove&lt;/a&gt;
                          &lt;/div&gt;
                          &lt;input type="hidden" name="order-pname" value="'.$product_name.'"&gt;
  &lt;input type="hidden" name="order-price" value=" '.$price.'"&gt;
  &lt;input type="hidden" name="order-qty" value="' . $each_item['quantity'] . '"&gt;
  &lt;input type="hidden" name="order-total" value="'.$pricetotal.'"&gt;
  &lt;input type="hidden" name="item-id" value="' . $item_id . '"&gt;
  
                           ';
                           $i++;
                           }
  </code></pre>
  
  <p>and i am closing my form tag in between my body tag.</p>
  
  <p>And the insert code is below</p>
  
  <pre><code>if(isset($_POST['place-order']))
  {
      $pid = $_POST['item-id'];
      $ocname = $_SESSION['fname'];
      $oclname = $_SESSION['lname'];
      $opname=$_POST['order-pname'];
      $oprice=$_POST['order-price'];
      $oqty=$_POST['order-qty'];
      $ototal=$_POST['order-total'];
      $email = $_SESSION['email'];
      $address=$_SESSION['address']; 
      $city=$_SESSION['city'];
      $state=$_SESSION['state'];
      $country=$_SESSION['country'];
      $zip= $_SESSION['zip'];
      $phone=$_SESSION['phone'];
      $sql =mysql_query("INSERT INTO orders (pid, customer_name, customer_lname, product_name, qty, price, total, date_added, customer_email, customer_address, customer_city, customer_state, customer_country, customer_zip, customer_phone ) VALUES('$pid','$ocname','$oclname', '$opname', '$oqty','$oprice','$ototal', now(), '$email','$address','$city','$state','$country','$zip','$phone' ) ") or die(mysql_error());
  
  }
  </code></pre>
  
  <p>So anybody please help me.</p>