gpt4 book ai didi

php - MySQL Query 双重查询

转载 作者:行者123 更新时间:2023-11-29 10:19:22 25 4
gpt4 key购买 nike

我尝试在 tbl_ordetails 中插入数据,然后更新 tbl_cart 中的数据,但是当我尝试插入数据时,结果总是“失败”,我不知道出了什么问题。请帮助我

<?php
include ("connection.php");
if(isset($_POST['btnSubmit']))
{




$fullname=$_POST['fullname'];
$address=$_POST['address'];
$phone_number=$_POST['phone_number'];
$city=$_POST['city'];
$customer=$_POST['customer'];

$query = "INSERT INTO tbl_orderdetails (fullname, address, phone_number, city, customer) VALUES ('$fullname, $address, $phone_number, $city, $customer')";
$query1 = "UPDATE tbl_cart SET status ='Ordered' WHERE customer=['$customer']";

$result = mysqli_query($conn, $query);

if(($conn->query($query1) === TRUE) && ($result->num_rows > 0)){
echo "success";
exit;

}
else{
echo "failed";
exit;

}


}
?>

提前致谢

最佳答案

您在...中缺少的引用负载

$query = "INSERT INTO tbl_orderdetails (fullname, address, phone_number, city, customer) 
VALUES ('$fullname, $address, $phone_number, $city, $customer')";

它获取所有值并构建 1 个值。应该是

$query = "INSERT INTO tbl_orderdetails (fullname, address, phone_number, city, customer) 
VALUES ('$fullname', '$address', '$phone_number', '$city', '$customer')";

您的更新应该是(减[])

$query1 = "UPDATE tbl_cart SET status ='Ordered' WHERE customer='$customer'";

更好的是使用准备好的语句并绑定(bind)变量。

更新:

   $result = $conn->query($query);
if ( $result === false ) {
echo "error:".$conn->error;
exit;
}

if($conn->query($query1) === TRUE){
echo "success";
exit;

}
else{
echo "failed:".$conn->error;
exit;

}

关于php - MySQL Query 双重查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49595568/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com