【发布时间】:2017-02-10 11:41:56
【问题描述】:
使用 Ajax 加载的数组插入将多个产品插入单个 id。也许使用 Explode 但需要明确说明这种类型的输出:
所有产品(问题)都将输入到一个 id 中。这些问题列表是由 Ajax 添加的。
<?php
if(isset($_POST['Submit'])){
try {
$serviceTitle = $_POST['serviceTitle'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$amount = $_POST['amount'];
$date = date('Y-m-d');
date_default_timezone_set('Asia/Dacca');
$time = date('h:i:s');
$createBy = $_SESSION['sess_username'];
$_SESSION['orderNo'] = $_POST['orderNo'];
$_SESSION['customerNo'] = $_POST['customerNo'];
if($_POST['Submit']==='Submit'){
for($i=0;$i<count($serviceTitle);$i++){
$statement = $db->prepare("INSERT INTO invoice (orderNo,customerNo,productName,price,quantity,amount,createDate,createTime,createBy) VALUES (?,?,?,?,?,?,?,?,?)");
$statement->execute(array($_POST['orderNo'],$_POST['customerNo'],$serviceTitle[$i],$price[$i],$quantity[$i],$amount[$i],$date,$time,$createBy));
}
}
header("location: order_confirm_tech_step2.php");
}
catch(Exception $e) {
$error_message = $e->getMessage();
}
}
?>
【问题讨论】:
-
与问题完全无关,但我想指出,“数量”的普遍接受的速记版本应该是“数量”,而不是“Qnt”