我想用来自表名customer的外键将会话数据存储到名为order的数据库表中,但数据未存储在order表中。无法理解原因。
<?php
session_start();
$conn= mysqli_connect("localhost","root","","onlinestore");
if(isset($_POST['customer']))
{
$fname= $_POST['fname'];
$lname= $_POST['lname'];
$email= $_POST['email'];
$country= $_POST['country'];
$city= $_POST['city'];
$address= $_POST['address'];
$zipcode= $_POST['zipcode'];
$phone_no= $_POST['phone_no'];
$query="insert into
customer(fname,lname,email,country,city,address,zip_code,phone_no)
values('$fname', '$lname', '$email', '$country', '$city', '$address',
'$zipcode', '$phone_no')";
$result= mysqli_query($conn, $query);
$c_id= mysqli_insert_id($conn);
echo $c_id;
$query1="";
if(isset($_SESSION['shopping_cart']))
{
foreach($_SESSION['shopping_cart'] as $key=> $rows){
$id= $rows['id'];
$name= $rows['name'];
$image= $rows['image'];
$price= $rows['price'];
$quantity= $rows['quantity'];
$c_id= mysqli_insert_id($conn);
$query1.="insert into
order(order_id,name,image,price,qty,customer_id)
values('$id','$name','$image','$price','$quantity','$c_id')";
}
if(mysqli_multi_query($conn,$query1))
{
echo "data inserted";}
}
}
?>