我试图弄清楚为什么我的 foreach 循环没有提供多个变量(第一个变量) - 我正在尝试创建一个电子商务网站,这是我的购物车的保存功能。两个 sql 语句都是正确的并进入我的数据库。
有两个表 - 一个发票表和另一个表,我将显示订购的产品。我正在使用重置功能来获取我在另一个功能中上传的图像的 ID。
有人有什么想法吗?
public static function submit()
{
$nOrderNum = date("Y-m-d").mt_rand();
$orderDate = date("Y-m-d h:m:s");
$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$address = $_POST["address"];
$imgID = AllMerch::getImgs();
$orderToggle = 0;
$value = reset($imgID);
$con = Db::connect();
mysqli_query($con,"
INSERT INTO invoice
(
nOrderNum,
strOrderDate,
strName,
strLast,
strEmail,
nPhone,
strAddress,
nPrice,
bOrderToggle
) VALUES (
'".$nOrderNum."',
'".$orderDate."',
'".$firstname."',
'".$lastname."',
'".$email."',
'".$phone."',
'".$address."',
'".Cart::checkoutTotal()."',
'".$orderToggle."'
)");
$invoiceID = mysqli_insert_id($con);
foreach($_SESSION["arrCart"] as $merch){
mysqli_query($con,"
INSERT INTO merch_history
(
nInvoiceID,
nProductsID,
nQty,
nPrice,
nImgID
) VALUES (
'".$invoiceID."',
'".$merch["id"]."',
'".$merch["currentQty"]."',
'".$merch["price"]."',
'".$value."'
)");
$sql = "UPDATE products SET nQty = nQty - '".$merch["currentQty"]."' WHERE id = '".$merch["id"]."'";
$sql = "UPDATE images SET nInvoiceID = '".$invoiceID."' WHERE nSessionID = '".$_SESSION['id']."'";
}
}
守着一只汪
鸿蒙传说