title: Php Shopping cart - Size and length for each quantity of a type of product
body: <p>I have been working on an online store. Project's aim is to add products to a shopping cart.. Customer should be able to change size &amp; length for each quantity for a product.
  Example :</p>
  
  <ul>
  <li>I sell a Product named A </li>
  <li>customer order 5 pieces of product A </li>
  <li>So he should be able to set 5 size and lengths for product A as the quantity is 5. </li>
  </ul>
  
  <p>Then TCPDF is also there to email the created invoice.</p>
  
  <p>I just want some help with the setting of sizes and length for each quantity. Please Please help..</p>
  
  <p>ALso if its possible please assist me with adding those lengths and sizes to the pdf created which is under function sendmail</p>
  
  <p>Following is the code i have written till now...</p>
  
  <pre><code>&lt;?php
  include("include/session.php");
  require_once('config/lang/eng.php');
  require_once('tcpdf.php');
  
  //Start the session
  session_start();
  
  //Create 'cart' if it doesn't already exist
  if (!isset($_SESSION['SHOPPING_CART'])){ $_SESSION['SHOPPING_CART'] = array(); }
  
  
  //Add an item only if we have the threee required pices of information: name, price, qty
  if (isset($_GET['add']) &amp;&amp; isset($_GET['price']) 
          &amp;&amp; isset($_GET['qty']) &amp;&amp; isset($_GET['size'])
          &amp;&amp; isset($_GET['length'])&amp;&amp; isset($_GET['code']) ){
      //Adding an Item
      //Store it in a Array
      $ITEM = array(
          //Item name
          'name' =&gt; $_GET['add'],
          //Item Price
          'price' =&gt; $_GET['price'],
          //Qty wanted of item
          'qty' =&gt; $_GET['qty'],
  
          'size' =&gt; $_GET['size'],
  
          'length' =&gt; $_GET['length'],
  
          'code' =&gt; $_GET['code']
      );
  
      //Add this item to the shopping cart
      $_SESSION['SHOPPING_CART'][] =  $ITEM;
      //Clear the URL variables
      header('Location: ' . $_SERVER['PHP_SELF']);
  }
  //Allowing the modification of individual items no longer keeps this a simple shopping cart.
  //We only support emptying and removing
  else if (isset($_GET['remove'])){
      //Remove the item from the cart
      unset($_SESSION['SHOPPING_CART'][$_GET['remove']]);
      //Re-organize the cart
      //array_unshift ($_SESSION['SHOPPING_CART'], array_shift ($_SESSION['SHOPPING_CART']));
      //Clear the URL variables
      header('Location: ' . $_SERVER['PHP_SELF']);
  }
  else if (isset($_GET['empty'])){
      //Clear Cart by destroying all the data in the session
      session_destroy();
      //Clear the URL variables
      header('Location: ' . $_SERVER['PHP_SELF']);
  }
  else if (isset($_POST['update'])) {
      //Updates Qty for all items
      foreach ($_POST['items_qty'] as $itemID =&gt; $qty) {
          //If the Qty is "0" remove it from the cart
          if ($qty == 0) {
              //Remove it from the cart
              unset($_SESSION['SHOPPING_CART'][$itemID]);
          }
          else if($qty &gt;= 1) {
              //Update to the new Qty
              $_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
          }
          foreach ($_POST['items_size'] as $itemID =&gt; $size) {
              //If the Qty is "0" remove it from the cart
              if($size &gt;= 1) {
                  //Update to the new Qty
                  $_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;
          }
      }
      foreach ($_POST['items_length'] as $itemID =&gt; $length) {
          //If the Qty is "0" remove it from the cart
  
          //Update to the new Qty
          $_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;
      }
  }
  //Clear the POST variables
  header('Location: ' . $_SERVER['PHP_SELF']);
  }
  $req_user = $session-&gt;username;
  $req_user_info = $database-&gt;getUserInfo($req_user);
  $need= $req_user;
  /* Username */
  $username=$req_user;
  
  $q = "SELECT name, address, city, country, postal, email, number, account, counter "
  ."FROM ".TBL_USERS." WHERE username = '$username'";
  $result = $database-&gt;query($q);
  $num_rows = mysql_numrows($result);
  
  
  for($i=0; $i&lt;$num_rows; $i++){
  $storename  = mysql_result($result,$i,"name");
  $address  = mysql_result($result,$i,"address");
  $city  = mysql_result($result,$i,"city");
  $country  = mysql_result($result,$i,"country");
  $postal  = mysql_result($result,$i,"postal");
  $email  = mysql_result($result,$i,"email");
  $number  = mysql_result($result,$i,"number");
  $account  = mysql_result($result,$i,"account");
  $counter  = mysql_result($result,$i,"counter");
  }
  
  
  ?&gt;
  function sendmail($storename,$address,$city,$country,$postal,$number, $email, $account, $counter){
  class MYP extends TCPDF {
  
  // Load table data from file
  public function LoadData($file) {
  // Read file lines
  $lines = file($file);
  $data = array();
  foreach($lines as $line) {
  $data[] = explode(';', chop($line));
  }
  return $data;
  }
  
  // Colored table
  public function ColoredTable($header, $account, $counter) {
  // Colors, line width and bold font
  $this-&gt;SetFillColor(255, 255, 255);
  $this-&gt;SetTextColor(0);
  $this-&gt;SetDrawColor(0, 0, 0);
  $this-&gt;SetLineWidth(0.3);
  $this-&gt;SetFont('', 'B');
  
  // Header
  $w = array(35, 40);
  $num_headers = count($header);
  for($i = 0; $i &lt; $num_headers; ++$i) {
  $this-&gt;Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
  }
  $this-&gt;Ln();
  // Color and font restoration
  $this-&gt;SetFillColor(255, 255, 255);
  $this-&gt;SetTextColor(0);
  $this-&gt;SetFont('');
  // Data
  $fill = 0;
  
  $ref = $account.$counter;
  $today = date("m.d.y");
  
  
  $this-&gt;Cell($w[0], 6, $today, 'LR', 0, 'C', $fill);
  $this-&gt;Cell($w[1], 6, $ref, 'LR', 0, 'C', $fill);
  $this-&gt;Ln();
  
  $fill=!$fill;
  
  $this-&gt;Cell(array_sum($w), 0, '', 'T');
  }
  public function ColoredTable2($header) {
  // Colors, line width and bold font
  $this-&gt;SetFillColor(255, 255, 255);
  $this-&gt;SetTextColor(0);
  $this-&gt;SetDrawColor(0, 0, 0);
  $this-&gt;SetLineWidth(0.3);
  $this-&gt;SetFont('', 'B');
  
  // Header
  $w = array(30, 40, 20,20,20,20);
  $num_headers = count($header);
  for($i = 0; $i &lt; $num_headers; ++$i) {
  $this-&gt;Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
  }
  $this-&gt;Ln();
  
  // Color and font restoration
  $this-&gt;SetFillColor(255, 255, 255);
  $this-&gt;SetTextColor(0);
  $this-&gt;SetFont('');
  // Data
  $fill = 0;
  $totalamount=0;
  foreach ($_SESSION['SHOPPING_CART'] as $itemNumber =&gt; $item) {
  $tot=$item['qty'] * $item['price'];
  $this-&gt;Cell($w[0], 6, $item['name'], 'LR', 0, 'C', $fill);
  $this-&gt;Cell($w[1], 6, $item['size'], 'LR', 0, 'C', $fill);
  $this-&gt;Cell($w[2], 6, $item['qty'], 'LR', 0, 'C', $fill);
  $this-&gt;Cell($w[3], 6, $item['length'], 'LR', 0, 'C', $fill);
  $this-&gt;Cell($w[4], 6, $item['price'], 'LR', 0, 'C', $fill);
  $this-&gt;Cell($w[5], 6, $tot, 'LR', 0, 'C', $fill);
  $this-&gt;Ln();
  $totalamount=$totalamount+$tot;
  $fill=!$fill;
  }
  
  
  $this-&gt;Cell(array_sum($w), 0, '', 'T');
  }
  public function ColoredTable1($header,$txt2,$txt3,$txt4,$txt5) {
  // Colors, line width and bold font
  $this-&gt;SetFillColor(255, 255, 255);
  $this-&gt;SetTextColor(0);
  $this-&gt;SetDrawColor(0, 0, 0);
  $this-&gt;SetLineWidth(0.3);
  $this-&gt;SetFont('', 'B');
  
  // Header
  $w = array(70);
  $num_headers = count($header);
  for($i = 0; $i &lt; $num_headers; ++$i) {
  $this-&gt;Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
  }
  $this-&gt;Ln();
  
  // Color and font restoration
  $this-&gt;SetFillColor(255, 255, 255);
  $this-&gt;SetTextColor(0);
  $this-&gt;SetFont('');
  // Data
  $fill = 0;
  
  $this-&gt;Cell($w[0], 6, $txt2, 'LR', 0, 'L', $fill);
  $this-&gt;Ln();
  $this-&gt;Cell($w[0], 6, $txt3, 'LR', 0, 'L', $fill);
  $this-&gt;Ln();
  $this-&gt;Cell($w[0], 6, $txt4, 'LR', 0, 'L', $fill);
  $this-&gt;Ln();
  $this-&gt;Cell($w[0], 6, $txt5, 'LR', 0, 'L', $fill);
  
  $this-&gt;Ln();
  $fill=!$fill;
  
  
  $this-&gt;Cell(array_sum($w), 0, '', 'T');
  }
  }
  function curPageName2() {
  return substr($_SERVER["SCRIPT_NAME"],strrpos($_SERVER["SCRIPT_NAME"],"/")+1);
  }
  
  
  $url= curPageName2();
  $len=strlen($url);
  $furl=substr($url,0,($len-4));
  $furl1=$furl.';1;2;3;4;5;6'."\n";
  
  $fp = fopen('cache/table_data_demo1.txt', 'w');
  fwrite($fp, $furl1);
  fclose($fp);
  
  
  
  // create new PDF document
  $pdf = new MYP(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
  
  // set document information
  $pdf-&gt;SetCreator(PDF_CREATOR);
  $pdf-&gt;SetAuthor('Nicola Asuni');
  $pdf-&gt;SetTitle('TCPDF Example INVOICE');
  $pdf-&gt;SetSubject('TCPDF Tutorial');
  $pdf-&gt;SetKeywords('TCPDF, PDF, example, test, guide');
  
  //Print all the items in the shopping cart
  // set default header data
  $pdf-&gt;SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.'                                   INVOICE', PDF_HEADER_STRING);
  
  // set header and footer fonts
  $pdf-&gt;setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
  $pdf-&gt;setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
  
  // set default monospaced font
  $pdf-&gt;SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
  
  //set margins
  $pdf-&gt;SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
  $pdf-&gt;SetHeaderMargin(PDF_MARGIN_HEADER);
  $pdf-&gt;SetFooterMargin(PDF_MARGIN_FOOTER);
  
  //set auto page breaks
  $pdf-&gt;SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
  
  //set image scale factor
  $pdf-&gt;setImageScale(PDF_IMAGE_SCALE_RATIO);
  
  //set some language-dependent strings
  $pdf-&gt;setLanguageArray($l);
  
  // ---------------------------------------------------------
  
  // set font
  $pdf-&gt;SetFont('times', '', 10);
  
  // add a page
  $pdf-&gt;AddPage();
  
  
  
  // set color for background
  $pdf-&gt;SetFillColor(255, 255, 127);
  
  // MultiCell($w, $h, $txt, $border=0, $align='J', $fill=0, $ln=1, $x='', $y='', $reseth=true, $stretch=0, $ishtml=false, $autopadding=true, $maxh=0)
  
  // set some text for example
  $txt = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.';
  $header = array('Tax Date', 'Invoice No.');
  
  $html = &lt;&lt;&lt;EOD
  &lt;p&gt;Suite-10&lt;br/&gt;3-11 Imperial Road&lt;br/&gt;London&lt;br/&gt;Greater London SW6 2AG&lt;br/&gt;&lt;br/&gt;&lt;/p&gt;
  EOD;
  
  $pdf-&gt;writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);
  
  $pdf-&gt;ColoredTable($header, $account, $counter);
  $html = &lt;&lt;&lt;EOD
  &lt;br /&gt;
  EOD;
  
  $pdf-&gt;writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
  
  $html = &lt;&lt;&lt;EOD
  &lt;br /&gt;
  EOD;
  // Print text using writeHTMLCell()
  $pdf-&gt;writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
  $txt2=$storename;
  $txt3=$address;
  $txt4=$city.",".$country.",".$postal;
  $txt5=$number;
  $header=array('Invoice To');
  $pdf-&gt;ColoredTable1($header,$txt2,$txt3,$txt4,$txt5);
  $html = &lt;&lt;&lt;EOD
  &lt;br /&gt;
  EOD;
  
  $pdf-&gt;writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
  
  
  
  $html = &lt;&lt;&lt;EOD
  &lt;br /&gt;
  EOD;
  $totamt = 0;
  foreach ($_SESSION['SHOPPING_CART'] as $itemNumber =&gt; $item) {
  $item['name'];
  $item['price'];
  $item['qty'];
  $tot=$item['qty'] * $item['price'];
  $item['size'];
  $item['length'];
  $totamt=$totamt+$tot;
  }
  
  
  // Print text using writeHTMLCell()
  $pdf-&gt;writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
  
  $header = array('Item', 'Size', 'Quantity','Length','Rate','Amount');
  ;
  $data = $pdf-&gt;LoadData('cache/table_data_demo1.txt');
  $pdf-&gt;ColoredTable2($header);
  
  $html = &lt;&lt;&lt;EOD
  &lt;br /&gt;
  EOD;
  
  $pdf-&gt;writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);
  
  
  
  $pdf-&gt;Ln(4);
  
  // set color for background
  $pdf-&gt;SetFillColor(220, 255, 220);
  $vat=(($totamt*20)/100);
  $final=$totamt+$vat;
  $vat1='   RATE     VAT     NET   ';
  $vat2='E@20%     '.$vat.'    '.$totamt;
  $vat3='Terms of Payment: Invoice to be paid immediately. All goods remain the property of Intuzuri UK Ltd until full payment has been received. Copyright in the designs listed above remain the property of Intuzuri UK Ltd. Intuzuri UK Ltd Registered in England Company No. 07880714. Company VAT Number : GB 134 9206 21';
  
  if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
  {
  $tot1='SUBTOTAL : '.'$'.$totamt;
  $tot2='VAT Total : '.'$'.$vat;
  $tot5='TOTAL : '.'$'.$final;
  $tot3='Payments/Credits : $0.00';
  $tot4='Balance Due : '.'$'.$final;
  }
  else
  {
  $tot1='SUBTOTAL : '.'GBP '.$totamt;
  $tot2='VAT Total : '."GBP ".$vat;
  $tot5='TOTAL : '."GBP ".$final;
  $tot3="Payments/Credits : GBP 0.00";
  $tot4='Balance Due : '."GBP ".$final;
  }
  $pdf-&gt;MultiCell(105, 50, $vat1."\n".$vat2."\n\n".$vat3, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'T');
  $pdf-&gt;MultiCell(65, 50,"\n\n".$tot1."\n\n".$tot2."\n\n".$tot3."\n\n".$tot4."\n\n".$tot5, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'M');
  
  // move pointer to last page
  $pdf-&gt;lastPage();
  
  // ---------------------------------------------------------
  
  //Close and output PDF document
  $pdf-&gt;Output('example_005.pdf', 'F');
  
  
  
  
  
  $date = $_POST["datepick"];
  $info = $_POST["TextArea1"];
  
  $fileatt = "example_005.pdf"; // Path to the file
  $fileatt_type = "application/pdf"; // File Type
  $fileatt_name = "Sales_Confirmation.pdf"; // Filename that will be used for the file as the attachment
  $email_from = ""; // Who the email is from
  $email_subject = "Sales Confirmation"; // The Subject of the email
  $email_message = "  ";
  $email_message .= "Retailer ".$storename.", has just placed an order. The Order Form is there in the attachment.&lt;br&gt;"
  ."Please Note Below are the additional details requested by the retailer. &lt;br&gt;"
  ."Expected Delivery Date : ".$date.".&lt;br&gt;"
  ."Additional Information : ".$info.".&lt;br&gt;"
  ."If you would like to Contact the seller, you can contact here : ".$email;
  $email_to = ""; // Who the email is to
  $headers = "From: ".$email_from;
  $file = fopen($fileatt,'rb');
  $data = fread($file,filesize($fileatt));
  fclose($file);
  $semi_rand = md5(time());
  $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
  $headers .= "\nMIME-Version: 1.0\n" .
  "Content-Type: multipart/mixed;\n" .
  " boundary=\"{$mime_boundary}\"";
  $email_message .= "This is a multi-part message in MIME format.\n\n" .
  "--{$mime_boundary}\n" .
  "Content-Type:text/html; charset=\"iso-8859-1\"\n" .
  "Content-Transfer-Encoding: 7bit\n\n" .
  $email_message .= "\n\n";
  $data = chunk_split(base64_encode($data));
  $email_message .= "--{$mime_boundary}\n" .
  "Content-Type: {$fileatt_type};\n" .
  " name=\"{$fileatt_name}\"\n" .
  //"Content-Disposition: attachment;\n" .
  //" filename=\"{$fileatt_name}\"\n" .
  "Content-Transfer-Encoding: base64\n\n" .
  $data .= "\n\n" .
  "--{$mime_boundary}--\n";
  $sent = @mail($email_to, $email_subject, $email_message, $headers);
  
  
  }
  
  
  
  if (isset($_POST['submit']))
  {
  $counter++;
  $field = "counter";
  $value= $counter;
  $database-&gt;updatecounter($username,$field,$value );
  //Everything is good, proceed
  sendmail($storename,$address,$city,$country,$postal,$number, $email, $account, $counter);
  
  $result_message = "Thank You, You order have been successfully placed, You will recieve an email shortly., ";
  }
  
  ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /&gt;
  &lt;title&gt;Intuzuri Retail Online Order Form&lt;/title&gt;
  &lt;script type="text/javascript" src="datepickr.js"&gt;&lt;/script&gt;
  
  &lt;style type="text/css"&gt;
  
  .calendar {
  font-family: 'Trebuchet MS', Tahoma, Verdana, Arial, sans-serif;
  font-size: 0.9em;
  background-color: #EEE;
  color: #333;
  border: 1px solid #DDD;
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  padding: 0.2em;
  width: 14em;
  }
  
  .calendar a {
  outline: none;
  }
  
  .calendar .months {
  background-color: #F6AF3A;
  border: 1px solid #E78F08;
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  color: #FFF;
  padding: 0.2em;
  text-align: center;
  }
  
  .calendar .prev-month,
  .calendar .next-month {
  padding: 0;
  }
  
  .calendar .prev-month {
  float: left;
  }
  
  .calendar .next-month {
  float: right;
  }
  
  .calendar .current-month {
  margin: 0 auto;
  }
  
  .calendar .months a {
  color: #FFF;
  text-decoration: none;
  padding: 0 0.4em;
  -moz-border-radius: 4px;
  -webkit-border-radius: 4px;
  border-radius: 4px;
  }
  
  .calendar .months a:hover {
  background-color: #FDF5CE;
  color: #C77405;
  }
  
  .calendar table {
  border-collapse: collapse;
  padding: 0;
  font-size: 0.8em;
  width: 100%;
  }
  
  .calendar th {
  text-align: center;
  }
  
  .calendar td {
  text-align: right;
  padding: 1px;
  width: 14.3%;
  }
  
  .calendar td a {
  display: block;
  color: #1C94C4;
  background-color: #F6F6F6;
  border: 1px solid #CCC;
  text-decoration: none;
  padding: 0.2em;
  }
  
  .calendar td a:hover {
  color: #C77405;
  background-color: #FDF5CE;
  border: 1px solid #FBCB09;
  }
  
  .calendar td.today a {
  background-color: #FFF0A5;
  border: 1px solid #FED22F;
  color: #363636;
  }
  
  &lt;/style&gt;
  &lt;style type="text/css"&gt;
  &lt;!--
  #formArea #orderForm #formColumns {
  width:800px;
  margin:auto;
  }
  #formArea #orderForm #formColumns #leftColumn {
  float:left;
  width:400px;
  }
  #orderForm {
  height:500px;
  }
  #formArea #orderForm #formColumns #rightColumn {
  float:right;
  width:400px;
  }
  #formArea #orderForm #formColumns th {
  text-align: left;
  }
  .copyright {
  font-size: 9pt;
  }
  --&gt;
  &lt;/style&gt;
  &lt;/head&gt;
  &lt;?
  /**
  * User has already logged in, so display relavent links, including
  * a link to the admin center if the user is an administrator.
  */
  if($session-&gt;logged_in){
  ?&gt;
  &lt;body&gt;
  &lt;div align="center"&gt;
  &lt;?
  echo "&lt;b&gt;$session-&gt;username&lt;/b&gt;, you are logged in. &lt;br&gt;&lt;br&gt;"
  ."[&lt;a href=\"userinfo.php?user=$session-&gt;username\"&gt;My Account&lt;/a&gt;] &amp;nbsp;&amp;nbsp;"
  ."[&lt;a href=\"useredit.php\"&gt;Edit Account&lt;/a&gt;] &amp;nbsp;&amp;nbsp;"
  ."[&lt;a href=\"process.php\"&gt;Logout&lt;/a&gt;] &amp;nbsp;&amp;nbsp;"
  ."[&lt;a href=\"index.php\"&gt;View Other Products&lt;/a&gt;]";
  ?&gt;
  &lt;/div&gt;
  &lt;div id="pageHeader"&gt;
  &lt;h1 align="center"&gt;View Your Order here&lt;/h1&gt;
  &lt;/div&gt;
  &lt;div id="shoppingCartDisplay"&gt;
  &lt;form action="" method="post" name="shoppingcart"&gt;
  &lt;?php
  //We want to include the shopping cart in the email
  ob_start();
  ?&gt;
  &lt;table align="center" width="800" border="1"&gt;
  &lt;tr align="center"&gt;
  &lt;th scope="col"&gt;&amp;nbsp;&lt;/th&gt;
  &lt;th scope="col"&gt;Item Name&lt;/th&gt;
  &lt;td scope="col"&gt;Unit Price ( &lt;?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
  {
  echo "$";
  }
  else
  {
  
  echo '&amp;#163;';
  }
  ?&gt; )&lt;/td&gt;
  &lt;th scope="col"&gt;Qty&lt;/th&gt;
  &lt;td scope="col"&gt;Cost ( &lt;?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
  {
  echo "$";
  }
  else
  {
  
  echo "&amp;#163;";
  }
  ?&gt; )&lt;/td&gt;
  &lt;th scope="col"&gt;Change Size&lt;/th&gt;
  &lt;th scope="col"&gt;Change Length&lt;/th&gt;
  
  &lt;/tr&gt;
  
  &lt;?php
  //Print all the items in the shopping cart
  foreach ($_SESSION['SHOPPING_CART'] as $itemNumber =&gt; $item) {
  ?&gt;
  &lt;tr align="center" id="item&lt;?php echo $itemNumber; ?&gt;"&gt;
  &lt;td&gt;&lt;a href="?remove=&lt;?php echo $itemNumber; ?&gt;"&gt;remove&lt;/a&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $item['name']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $item['price']; ?&gt;&lt;/td&gt;
  &lt;td&gt;&lt;input name="items_qty[&lt;?php echo $itemNumber; ?&gt;]" type="text" id="item&lt;?php echo $itemNumber; ?&gt;_qty" value="&lt;?php echo $item['qty']; ?&gt;" size="2" maxlength="3" /&gt;&lt;/td&gt;
  &lt;td&gt;&lt;?php echo $item['qty'] * $item['price']; ?&gt;&lt;/td&gt;
  
  &lt;td&gt;&lt;select name="items_size[&lt;?php echo $itemNumber; ?&gt;]" value="&lt;?php echo $item['size']; ?&gt;" type="text" id="item&lt;?php echo $itemNumber; ?&gt;_size" &gt;
  &lt;option selected="selected" value="&lt;?php echo $item['size']; ?&gt;"&gt;&lt;?php echo $item['size']; ?&gt;&lt;/option&gt;
  &lt;option value="2"&gt;2&lt;/option&gt;
  &lt;option value="4"&gt;4&lt;/option&gt;
  &lt;option value="6"&gt;6&lt;/option&gt;
  &lt;option value="8"&gt;8&lt;/option&gt;
  &lt;option value="10"&gt;10&lt;/option&gt;
  &lt;option value="12"&gt;12&lt;/option&gt;
  &lt;option value="14"&gt;14&lt;/option&gt;
  &lt;option value="16"&gt;16&lt;/option&gt;
  &lt;option value="18"&gt;18&lt;/option&gt;
  &lt;option value="20"&gt;20&lt;/option&gt;
  &lt;option value="22"&gt;22&lt;/option&gt;
  &lt;option value="24"&gt;24&lt;/option&gt;
  &lt;option value="26"&gt;26&lt;/option&gt;
  &lt;option value="28"&gt;28&lt;/option&gt;
  &lt;option value="30"&gt;30&lt;/option&gt;
  
  &lt;/select&gt;
  &lt;?php
  $order=strtotime("now");
  
  if($cntry == "USA" || $cntry =="United States Of America" || $cntry == "America")
  {
  $price=100;
  }
  else
  {
  $price=200;
  }
  
  ?&gt;
  &lt;td&gt;&lt;select name="items_length[&lt;?php echo $itemNumber; ?&gt;]" type="text" select="&lt;?php echo $item['length']; ?&gt;" id="item&lt;?php echo $itemNumber; ?&gt;_length" &gt;
  &lt;option selected="selected" value="&lt;?php echo $item['length']; ?&gt;"&gt;&lt;?php echo $item['length']; ?&gt;&lt;/option&gt;
  &lt;option value="46"&gt;46&lt;/option&gt;
  &lt;option value="48"&gt;48&lt;/option&gt;
  &lt;option value="50"&gt;50&lt;/option&gt;
  
  
  &lt;/select&gt;
  
  &lt;/tr&gt;
  &lt;?php
  }
  ?&gt;
  &lt;/table&gt;
  &lt;?php $_SESSION['SHOPPING_CART_HTML'] = ob_get_flush(); ?&gt;
  &lt;p&gt;
  &lt;div align="center"&gt;
  Please Make all you selections first (Quantity, Size, Length) and then update.&lt;br /&gt;&lt;br /&gt;&lt;input type="submit" name="update" id="update" value="Update Cart" /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;a href="index.php"&gt;Keep Shopping&lt;/a&gt;
  
  &lt;/div&gt;
  &lt;/p&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  
  
  &lt;div id="formArea"&gt;
  &lt;?php if (isset($result_message)) {?&gt;
  &lt;div align="center"&gt;&lt;h3&gt;&lt;?php echo $result_message; ?&gt;&lt;/h3&gt;&lt;/div&gt;
  &lt;?
  }
  else {
  ?&gt;
  &lt;p align="center"&gt;Once selected all your dresses, please submit your order after reviewing your account details.&lt;/p&gt;
  &lt;div id="orderForm"&gt;
  &lt;form action="" method="post" name="orderform"&gt;
  &lt;div id="formColumns"&gt;
  &lt;div id="leftColumn"&gt;
  
  &lt;table width="100%"  border="0" cellpadding="5" cellspacing="0"&gt;
  
  &lt;p align="center"&gt;&lt;b&gt;Your Account Information&lt;/b&gt;&lt;/p&gt;
  &lt;tr height="21"&gt;
  &lt;td height="21"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;b&gt;Store Name &lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;td height="21"&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;?php echo $storename; ?&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;b&gt;Email Address &lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;? echo $email; ?&gt;
  &lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;b&gt;Phone Number &lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;td&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;? echo $number; ?&gt;
  &lt;/font&gt;&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;&lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;&lt;b&gt;Billing Address&lt;/b&gt;&lt;/font&gt;&lt;/td&gt;
  &lt;td&gt;&lt;? echo $address.',&amp;nbsp&lt;br&gt;'
  ."$city, $country, $postal"; ?&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  
  &lt;div id="rightColumn"&gt;
  &lt;table width="100%" height="50%"  border="0" cellpadding="3" cellspacing="0"&gt;
  &lt;p align="center"&gt;&lt;b&gt;Additional Information&lt;/b&gt;&lt;/p&gt;
  
  &lt;tr&gt;
  &lt;td align="left"&gt;
  &lt;div align="left"&gt;
  &lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Expected Delivery Date:&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;                                                &lt;/td&gt;
  
  &lt;td&gt;
  &lt;input required="required" id="datepick" name="datepick" class="date-pick" /&gt;
  
  &lt;script type="text/javascript"&gt;
  new datepickr('datepick', { dateFormat: 'm-d-Y' });
  &lt;/script&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;div align="left"&gt;
  &lt;font size="2" face="Verdana, Arial, Helvetica, sans-serif"&gt;Additional Details:&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;/div&gt;                                                &lt;/td&gt;
  &lt;td&gt;
  &lt;textarea  id="TextArea1" name="TextArea1" cols="20" rows="8"&gt;&lt;/textarea&gt;
  &lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;
  &lt;div align="left"&gt;
  &lt;input name="submit" type="submit" id="submit" value="Submit"&gt;&lt;/div&gt;                                                &lt;/td&gt;
  &lt;td style="color: red;"&gt;
  *Before submitting please verify that all details are correct.
  &lt;/td&gt;
  
  &lt;/tr&gt;
  
  &lt;tr&gt;
  &lt;td&gt;
  &lt;div align="left"&gt;                                                      &lt;/div&gt;                                              &lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;?php } ?&gt;
  &lt;/div&gt;
  &lt;?
  }
  else
  {
  echo '&lt;META HTTP-EQUIV="Refresh" Content="0; URL=main.php"&gt;';
  
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>
  
  <p>I tried to do it by creating another session but cant seem to get it done myself. </p>
  
  <p>I wanted to make it like... when you will change the quantity to 5... so there should appear 5 dropdowns for size and 5 for length. I could make the dropdowns but couldnt store the selected value in the session. </p>
  
  <p>Any help is appreciated.</p>
  
  <p>To help this explain, Theres a session named Shopping Cart. Now that has array items like price size quantity etc. Now there a function :-     </p>
  
  <pre><code>else if (isset($_POST['update'])) {
  //Updates Qty for all items
  foreach ($_POST['items_qty'] as $itemID =&gt; $qty) {
  //If the Qty is "0" remove it from the cart
  if ($qty == 0) {
  //Remove it from the cart
  unset($_SESSION['SHOPPING_CART'][$itemID]);
  }
  else if($qty &gt;= 1) {
  //Update to the new Qty
  $_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
  
  }
  foreach ($_POST['items_size'] as $itemID =&gt; $size) {
  //If the Qty is "0" remove it from the cart
  if($size &gt;= 1) {
  //Update to the new Qty
  $_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;
  
  }
  }
  foreach ($_POST['items_length'] as $itemID =&gt; $length) {
  //If the Qty is "0" remove it from the cart
  
  //Update to the new Qty
  $_SESSION['SHOPPING_CART'][$itemID]['length'] = $length;
  
  
  }
  } 
  </code></pre>
  
  <p>Here its updating the size and length for each product. I want it for each quantity. For ex if you select 5 quantity customer should be able to select 5 sizes and 5 lengths current can only chose 1 each no matter how big the quantity is.. Maybe this will help you understand</p>