我希望以下代码在customer_payment表中插入cars id,但它只选择477 id。我不知道为什么。因为它可以在图像波纹管中看到只有product_id 477插入而不是任何其他如果我选择500它仍然插入477.请帮助我这个帮助将不胜感激。谢谢
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>";
}
*/
}
?>
答案 0 :(得分:1)
你在这里想做什么
$select_cart = "select * from cart";
$runcart = mysqli_query($conn, $select_cart);
$cartwhile=mysqli_fetch_assoc($runcart); // here
从“购物车”中提取第一个条目。表格总是会相同。
你可以尝试这样的事情。
$c_id = $_SESSION['customer_id'];
$select_cart = "select * from cart where C_ID=$c_id";
$runcart = mysqli_query($conn, $select_cart);
$cartwhile=mysqli_fetch_assoc($runcart);
此查询将专门为当前会话的客户提取数据。 您可以按原样使用的其余代码。