Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/298.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php购物车-每种产品数量的大小和长度_Php_Tcpdf - Fatal编程技术网

Php购物车-每种产品数量的大小和长度

Php购物车-每种产品数量的大小和长度,php,tcpdf,Php,Tcpdf,我一直在一家网上商店工作。该项目的目标是将产品添加到购物车中。。客户应能够更改产品每种数量的尺寸和长度。 例如: 我卖一种叫a的产品 客户订购5件产品A 因此,他应该能够为产品A设置5个尺寸和长度,因为数量为5 然后,TCPDF也可以通过电子邮件发送创建的发票 我只是想在设置每种数量的尺寸和长度方面得到一些帮助。请帮忙 如果可能,请帮助我将这些长度和大小添加到sendmail函数下创建的pdf中 下面是我到现在为止写的代码 <?php include("include/session.

我一直在一家网上商店工作。该项目的目标是将产品添加到购物车中。。客户应能够更改产品每种数量的尺寸和长度。 例如:

  • 我卖一种叫a的产品
  • 客户订购5件产品A
  • 因此,他应该能够为产品A设置5个尺寸和长度,因为数量为5
然后,TCPDF也可以通过电子邮件发送创建的发票

我只是想在设置每种数量的尺寸和长度方面得到一些帮助。请帮忙

如果可能,请帮助我将这些长度和大小添加到sendmail函数下创建的pdf中

下面是我到现在为止写的代码

<?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']) && isset($_GET['price']) 
        && isset($_GET['qty']) && isset($_GET['size'])
        && isset($_GET['length'])&& isset($_GET['code']) ){
    //Adding an Item
    //Store it in a Array
    $ITEM = array(
        //Item name
        'name' => $_GET['add'],
        //Item Price
        'price' => $_GET['price'],
        //Qty wanted of item
        'qty' => $_GET['qty'],

        'size' => $_GET['size'],

        'length' => $_GET['length'],

        'code' => $_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 => $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 >= 1) {
            //Update to the new Qty
            $_SESSION['SHOPPING_CART'][$itemID]['qty'] = $qty;
        }
        foreach ($_POST['items_size'] as $itemID => $size) {
            //If the Qty is "0" remove it from the cart
            if($size >= 1) {
                //Update to the new Qty
                $_SESSION['SHOPPING_CART'][$itemID]['size'] = $size;
        }
    }
    foreach ($_POST['items_length'] as $itemID => $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->username;
$req_user_info = $database->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->query($q);
$num_rows = mysql_numrows($result);


for($i=0; $i<$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");
}


?>
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->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');

// Header
$w = array(35, 40);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();
// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;

$ref = $account.$counter;
$today = date("m.d.y");


$this->Cell($w[0], 6, $today, 'LR', 0, 'C', $fill);
$this->Cell($w[1], 6, $ref, 'LR', 0, 'C', $fill);
$this->Ln();

$fill=!$fill;

$this->Cell(array_sum($w), 0, '', 'T');
}
public function ColoredTable2($header) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');

// Header
$w = array(30, 40, 20,20,20,20);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();

// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;
$totalamount=0;
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
$tot=$item['qty'] * $item['price'];
$this->Cell($w[0], 6, $item['name'], 'LR', 0, 'C', $fill);
$this->Cell($w[1], 6, $item['size'], 'LR', 0, 'C', $fill);
$this->Cell($w[2], 6, $item['qty'], 'LR', 0, 'C', $fill);
$this->Cell($w[3], 6, $item['length'], 'LR', 0, 'C', $fill);
$this->Cell($w[4], 6, $item['price'], 'LR', 0, 'C', $fill);
$this->Cell($w[5], 6, $tot, 'LR', 0, 'C', $fill);
$this->Ln();
$totalamount=$totalamount+$tot;
$fill=!$fill;
}


$this->Cell(array_sum($w), 0, '', 'T');
}
public function ColoredTable1($header,$txt2,$txt3,$txt4,$txt5) {
// Colors, line width and bold font
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetDrawColor(0, 0, 0);
$this->SetLineWidth(0.3);
$this->SetFont('', 'B');

// Header
$w = array(70);
$num_headers = count($header);
for($i = 0; $i < $num_headers; ++$i) {
$this->Cell($w[$i], 7, $header[$i], 1, 0, 'C', 1);
}
$this->Ln();

// Color and font restoration
$this->SetFillColor(255, 255, 255);
$this->SetTextColor(0);
$this->SetFont('');
// Data
$fill = 0;

$this->Cell($w[0], 6, $txt2, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt3, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt4, 'LR', 0, 'L', $fill);
$this->Ln();
$this->Cell($w[0], 6, $txt5, 'LR', 0, 'L', $fill);

$this->Ln();
$fill=!$fill;


$this->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->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example INVOICE');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');

//Print all the items in the shopping cart
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE.'                                   INVOICE', PDF_HEADER_STRING);

// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

//set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

//set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

//set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

//set some language-dependent strings
$pdf->setLanguageArray($l);

// ---------------------------------------------------------

// set font
$pdf->SetFont('times', '', 10);

// add a page
$pdf->AddPage();



// set color for background
$pdf->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 = <<<EOD
<p>Suite-10<br/>3-11 Imperial Road<br/>London<br/>Greater London SW6 2AG<br/><br/></p>
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='L', $autopadding=true);

$pdf->ColoredTable($header, $account, $counter);
$html = <<<EOD
<br />
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);

$html = <<<EOD
<br />
EOD;
// Print text using writeHTMLCell()
$pdf->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->ColoredTable1($header,$txt2,$txt3,$txt4,$txt5);
$html = <<<EOD
<br />
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);



$html = <<<EOD
<br />
EOD;
$totamt = 0;
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
$item['name'];
$item['price'];
$item['qty'];
$tot=$item['qty'] * $item['price'];
$item['size'];
$item['length'];
$totamt=$totamt+$tot;
}


// Print text using writeHTMLCell()
$pdf->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->LoadData('cache/table_data_demo1.txt');
$pdf->ColoredTable2($header);

$html = <<<EOD
<br />
EOD;

$pdf->writeHTMLCell($w=0, $h=0, $x='', $y='', $html, $border=0, $ln=1, $fill=0, $reseth=true, $align='', $autopadding=true);



$pdf->Ln(4);

// set color for background
$pdf->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->MultiCell(105, 50, $vat1."\n".$vat2."\n\n".$vat3, 1, 'C', 0, 0, '', '', true, 0, false, true, 40, 'T');
$pdf->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->lastPage();

// ---------------------------------------------------------

//Close and output PDF document
$pdf->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.<br>"
."Please Note Below are the additional details requested by the retailer. <br>"
."Expected Delivery Date : ".$date.".<br>"
."Additional Information : ".$info.".<br>"
."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->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., ";
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Intuzuri Retail Online Order Form</title>
<script type="text/javascript" src="datepickr.js"></script>

<style type="text/css">

.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;
}

</style>
<style type="text/css">
<!--
#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;
}
-->
</style>
</head>
<?
/**
* User has already logged in, so display relavent links, including
* a link to the admin center if the user is an administrator.
*/
if($session->logged_in){
?>
<body>
<div align="center">
<?
echo "<b>$session->username</b>, you are logged in. <br><br>"
."[<a href=\"userinfo.php?user=$session->username\">My Account</a>] &nbsp;&nbsp;"
."[<a href=\"useredit.php\">Edit Account</a>] &nbsp;&nbsp;"
."[<a href=\"process.php\">Logout</a>] &nbsp;&nbsp;"
."[<a href=\"index.php\">View Other Products</a>]";
?>
</div>
<div id="pageHeader">
<h1 align="center">View Your Order here</h1>
</div>
<div id="shoppingCartDisplay">
<form action="" method="post" name="shoppingcart">
<?php
//We want to include the shopping cart in the email
ob_start();
?>
<table align="center" width="800" border="1">
<tr align="center">
<th scope="col">&nbsp;</th>
<th scope="col">Item Name</th>
<td scope="col">Unit Price ( <?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
echo "$";
}
else
{

echo '&#163;';
}
?> )</td>
<th scope="col">Qty</th>
<td scope="col">Cost ( <?php if(strtolower($country) == "usa" || strtolower($country) =="united states of america" || strtolower($country) == "america")
{
echo "$";
}
else
{

echo "&#163;";
}
?> )</td>
<th scope="col">Change Size</th>
<th scope="col">Change Length</th>

</tr>

<?php
//Print all the items in the shopping cart
foreach ($_SESSION['SHOPPING_CART'] as $itemNumber => $item) {
?>
<tr align="center" id="item<?php echo $itemNumber; ?>">
<td><a href="?remove=<?php echo $itemNumber; ?>">remove</a></td>
<td><?php echo $item['name']; ?></td>
<td><?php echo $item['price']; ?></td>
<td><input name="items_qty[<?php echo $itemNumber; ?>]" type="text" id="item<?php echo $itemNumber; ?>_qty" value="<?php echo $item['qty']; ?>" size="2" maxlength="3" /></td>
<td><?php echo $item['qty'] * $item['price']; ?></td>

<td><select name="items_size[<?php echo $itemNumber; ?>]" value="<?php echo $item['size']; ?>" type="text" id="item<?php echo $itemNumber; ?>_size" >
<option selected="selected" value="<?php echo $item['size']; ?>"><?php echo $item['size']; ?></option>
<option value="2">2</option>
<option value="4">4</option>
<option value="6">6</option>
<option value="8">8</option>
<option value="10">10</option>
<option value="12">12</option>
<option value="14">14</option>
<option value="16">16</option>
<option value="18">18</option>
<option value="20">20</option>
<option value="22">22</option>
<option value="24">24</option>
<option value="26">26</option>
<option value="28">28</option>
<option value="30">30</option>

</select>
<?php
$order=strtotime("now");

if($cntry == "USA" || $cntry =="United States Of America" || $cntry == "America")
{
$price=100;
}
else
{
$price=200;
}

?>
<td><select name="items_length[<?php echo $itemNumber; ?>]" type="text" select="<?php echo $item['length']; ?>" id="item<?php echo $itemNumber; ?>_length" >
<option selected="selected" value="<?php echo $item['length']; ?>"><?php echo $item['length']; ?></option>
<option value="46">46</option>
<option value="48">48</option>
<option value="50">50</option>


</select>

</tr>
<?php
}
?>
</table>
<?php $_SESSION['SHOPPING_CART_HTML'] = ob_get_flush(); ?>
<p>
<div align="center">
Please Make all you selections first (Quantity, Size, Length) and then update.<br /><br /><input type="submit" name="update" id="update" value="Update Cart" />&nbsp;&nbsp;&nbsp;&nbsp;<a href="index.php">Keep Shopping</a>

</div>
</p>
</form>
</div>


<div id="formArea">
<?php if (isset($result_message)) {?>
<div align="center"><h3><?php echo $result_message; ?></h3></div>
<?
}
else {
?>
<p align="center">Once selected all your dresses, please submit your order after reviewing your account details.</p>
<div id="orderForm">
<form action="" method="post" name="orderform">
<div id="formColumns">
<div id="leftColumn">

<table width="100%"  border="0" cellpadding="5" cellspacing="0">

<p align="center"><b>Your Account Information</b></p>
<tr height="21">
<td height="21"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Store Name </b></font></td>
<td height="21"><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><?php echo $storename; ?></font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Email Address </b></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $email; ?>
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Phone Number </b></font></td>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><? echo $number; ?>
</font></td>
</tr>
<tr>
<td><font size="2" face="Verdana, Arial, Helvetica, sans-serif"><b>Billing Address</b></font></td>
<td><? echo $address.',&nbsp<br>'
."$city, $country, $postal"; ?>
</td>
</tr>

<tr>
<td>
</tr>
<tr>
</tr>
</table>
</div>

<div id="rightColumn">
<table width="100%" height="50%"  border="0" cellpadding="3" cellspacing="0">
<p align="center"><b>Additional Information</b></p>

<tr>
<td align="left">
<div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Expected Delivery Date:&nbsp;&nbsp;</font></div>                                                </td>

<td>
<input required="required" id="datepick" name="datepick" class="date-pick" />

<script type="text/javascript">
new datepickr('datepick', { dateFormat: 'm-d-Y' });
</script>
</td>
</tr>
<tr>
<td>
<div align="left">
<font size="2" face="Verdana, Arial, Helvetica, sans-serif">Additional Details:&nbsp;&nbsp;</font></div>                                                </td>
<td>
<textarea  id="TextArea1" name="TextArea1" cols="20" rows="8"></textarea>
</td>
</tr>
<tr>
<td>
<div align="left">
<input name="submit" type="submit" id="submit" value="Submit"></div>                                                </td>
<td style="color: red;">
*Before submitting please verify that all details are correct.
</td>

</tr>

<tr>
<td>
<div align="left">                                                      </div>                                              </td>
</tr>
</table>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
<?php } ?>
</div>
<?
}
else
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL=main.php">';

}
?>
</body>
</html> 

这里更新了每个产品的尺寸和长度。每种数量我都要。例如,如果您选择5个数量,客户应能够选择5种尺寸和5种长度,无论数量有多大,当前只能选择1个。。也许这有助于您理解

首先,您需要通过项目的id在会话中存储项目,而不是通过项目的名称或自动生成的索引。如果名称更改,您将无法在数据库中找到它们。您希望在
$\u会话['SHOPPING\u CART']['item\u id']=array()
中直接使用该id,因为这将允许您快速查找项目并使用它

由于同一项有多个实体,因此需要使用更复杂的数组来存储它们。简单的解决方案如下:

$ITEM = array(
    'name' => $_GET['add'],
    'qty' => $_GET['qty'],
    'price' => $_GET['price'] * $_GET['qty'],
    'size' => array_fill(0, $_GET['qty'], $_GET['size']),
    'length' => array_fill(0, $_GET['qty'], $_GET['length']),
    'code' => $_GET['code']
);
$_SESSION['SHOPPING_CART'][ $_GET['item_id'] ] =  $ITEM;
当用户想要更改数据时,可以为大小和长度数组中的每一行创建下拉列表,然后相应地保存它们

然而,我建议使用某种
用户id
将这些数据存储在数据库中。在当前的设计中,若用户意外地关闭了浏览器,或者只是在会话到期时返回,那个么他的整个订单都将丢失

编辑:处理尺寸和长度

foreach ($_SESSION['SHOPPING_CART'] as $item_id => $item)
{
    echo '<p>Name: ' . $item['name'] . ' for ' . $item['price'] . '$</p>';
    foreach($item['size'] as $j => $size)
    {
        echo '<p>#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '</p>';
    }
}
foreach($\u会话['SHOPPING\u CART']作为$item\u id=>$item)
{
回显“Name:”.$item['Name']”代表“$item['price']”。$

”; foreach($j=>$size的项目['size'] { 回显“#”。$j.”:大小“$size.”,长度“$item['length'][$j]”。

; } }

将echo替换为用于编辑的输入,并将其放入表单中。

澄清您的问题,并指向导致问题的代码。有一个名为“购物车”的会话。现在有了价格、大小、数量等数组项。现在有了一个函数:-嗨,谢谢你的回复。实际上,“大小”=>array\u fill(0,$\u GET['qty'],$\u GET['size'],“长度”=>array\u fill(0,$\u GET['qty'],$\u GET['length']),这会根据数量存储所有大小和长度的选定下拉值吗?此外,存储购物车数据实际上不是必要的,因为客户将进行即时购买。我的意思是,我现在应该如何使用大小和长度?通过像我当前运行的那样运行for-each循环?当客户在购物车中添加5个项目时,您不知道他想要哪种尺寸,我假设他选择了一种尺寸。因此,您可以制作所有大小和长度相同的项目。然后,如果他愿意,他可以编辑它,所以你在一个循环中回显所有大小和长度(因为它们是数组),并在他选择不同选项时更新我只有国家列表,没有链接。您不希望在订单页面显示10个下拉列表。您只想显示数量、一个尺寸和一个长度。然后,若用户选择多个,在购物车页面,他将能够选择大小。不要把它全部放在一个页面上,实际上我的购物车在order.php中,我知道这听起来很奇怪,但无论我是为谁做的,都希望它是这样的。你有什么建议?
foreach ($_SESSION['SHOPPING_CART'] as $item_id => $item)
{
    echo '<p>Name: ' . $item['name'] . ' for ' . $item['price'] . '$</p>';
    foreach($item['size'] as $j => $size)
    {
        echo '<p>#' . $j . ': size ' . $size . ', length ' . $item['length'][$j] . '</p>';
    }
}