-20
我想要下面的代碼在customer_payment表中插入汽車ID,但它只選擇477 ID。我不知道爲什麼。如圖所示,只有product_id 477被插入,如果我選擇500,它仍然會插入477.請幫助我獲得此幫助。謝謝 爲什麼正確的ID沒有插入表
include 'admin/db.php';
if(isset($_GET['payment_here'])){
//select product id from cart
$select_cart = "select * from cart";
$runcart = mysqli_query($conn, $select_cart);
$cartwhile=mysqli_fetch_assoc($runcart);
$carssid = $cartwhile['P_ID'];
$cusid = $cartwhile['C_ID'];
//select id from cars
$scars = "select * from cars where id=$carssid";
$scarsrun = mysqli_query($conn, $scars);
$showcars = mysqli_fetch_assoc($scarsrun);
$carsdealer = $showcars['dealer'];
//select customer id from customer table
//$selectcust = "select * from customer_register where id=$cusid";
//insert data into customer payment table
echo $insertpay = "insert into customer_payment
(Product_id, customer_id, dealer)
values ($carssid," . $_SESSION['customer_id'] . ", '$carsdealer')";
$run_inserts = mysqli_query($conn, $insertpay);
/*
if($run_inserts){
echo "<script>window.location.href = 'checkout.php'</script>";
}
*/
}
?>
它確實輸入了登錄的客戶ID,如圖3所示。這很好,問題出在product_id上,爲什麼它只選擇了477個產品ID。 –
,因爲購物車表中的**第一個條目**必須將customer_id設爲477. – nikamanish
您正在從當前會話插入**客戶ID,但您沒有根據當前customer_id獲取**數據。 – nikamanish