我想将会话购物车插入数据库mysql
这是我的代码
foreach($_SESSION['cart'] as $productid => $qty){
$query3 = "INSERT INTO dtransaction(trans_id, pro_id, quantity) VALUES ('$new', '$productid', '$qty')";
$query4 = mysqli_query($con, $query3);
print_r($query3."<br>");
}
print_r的结果
INSERT INTO dtransaction(trans_id, pro_id, quantity) VALUES ('TR033', '21', '1')
INSERT INTO dtransaction(trans_id, pro_id, quantity) VALUES ('TR033', '16', '2')
INSERT INTO dtransaction(trans_id, pro_id, quantity) VALUES ('TR033', '13', '8')
INSERT INTO dtransaction(trans_id, pro_id, quantity) VALUES ('TR033', '12', '3')
我对detail_id使用auto_increament(int) 但是在数据库中,像这样插入
detail_id trans_id pro_id quantity
197 TR034 21 1
201 TR035 21 1
detail_id跳转4,pro_id和数量只插入第一个数据
我想要的是这样的
detail_id trans_id pro_id quantity
198 TR034 21 1
199 TR034 16 2
200 TR034 13 8
201 TR034 12 3
怎么做?抱歉我的英文不好