为什么每次将$ orderid每次增加2?应该如何解决?
<?php
session_start();
include 'db_connect.php';
$orderdate = date("Y/m/d");
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$address = $_POST['streetaddress'];
$bldg = $_POST['bldg'];
$floor = $_POST['floor'];
$grandTotal = $_POST['grandtotal'];
$sql="INSERT INTO orders (order_date, client_firstname, client_lastname, client_phone, client_city, client_address, client_bldg, client_floor, grandtotal)
VALUES ('$orderdate', '$firstname', '$lastname', '$phone', '$city', '$address', '$bldg', '$floor', '$grandTotal');";
$r=$connect->prepare($sql);
$r->execute();
foreach($_SESSION as $key => $values){
if(strpos($key, "pid") == true)
{
$sql="select * from products LEFT JOIN category on products.category_id = category.category_id where product_id = $_SESSION[$key]";
$result = mysqli_query($connect, $sql);
$r = mysqli_fetch_assoc($result);
$w = "weight";
$w .= (string) $r['product_id'];
$weight = $_SESSION[$w];
$total = $r['product_price']*$weight;
$orderItemSql ="INSERT INTO order_item (order_id, product_id, product_price, product_weight, total)
VALUES ('1',''".$r['product_id']."', '".$r['product_price']."', '$weight','$grandTotal')";
$g=$connect->prepare($orderItemSql);
$g->execute();
}
}
$order_id;
if($connect->query($sql) === true) {
$order_id = $connect->insert_id;
$valid['order_id'] = $order_id;
}
$ orderid一次加2,这将如何解决?
和$ orderItemSql无法运行,也许是因为$ orderid?我试图在语句中插入$ orderid一个标准数字,但是它仍然无法正常工作。无法弄清楚您的帮助将不胜感激!谢谢
此有效