0
這是我的代碼,用於將我的數據插入到購物車中的數據庫中。當購物車中只有1個數據時,問題是否有效。如果購物車中有超過1件商品,我如何使它工作。我將它發送到數據庫的原因是,管理員可以查看訂單以準備它。將購物車數據插入到數據庫中
<?php
require_once('auth.php');
?>
<?php
include("dbase.php");
include("functions.php");
if(isset($_REQUEST['command'])){
if($_REQUEST['command']=='update'){
$name=$_REQUEST['name'];
$address=$_REQUEST['address'];
$sum=get_order_total('grandTotal');
$result=mysql_query("insert into bloom_customers values('','$name','$address','$phone','$sum','$date','$time','$banks')");
$customer_id=mysql_insert_id();
$date=date('Y-m-d');
$result=mysql_query("insert into bloom_orders values('','$date','$customer_id')");
$orderid=mysql_insert_id();
$max=count($_SESSION['cart']);
for($i=0;$i<$max;$i++){
$proid=$_SESSION['cart'][$i]['product_id'];
$q=$_SESSION['cart'][$i]['qty'];
$price=get_price($proid);
mysql_query("insert into order_details values ($orderid,$proid,$q,$price,$customer_id)");
$customer_id=mysql_insert_id();
}
echo "<script type='text/javascript'>window.location='ordersubmitted.php' </script>";
}
}
?>
也許你不應該在的塊中的最後一行覆蓋CUSTOMER_ID? – fejese
此外,您應該考慮成功後重定向header()調用,而不是使用js。 – fejese
你是否在你的$ max變量中獲得所有項目? – bentham