gpt4 book ai didi

mysql - 错误: You have an error in your SQL syntax INSERT with BIND PARAM

转载 作者:行者123 更新时间:2023-11-29 12:29:02 27 4
gpt4 key购买 nike

我无法用这段代码解决问题,可能是语法sql问题。

尝试以多种方式更改 INSERT sql 标记。我不知道是否需要使用单引号。已经尝试过。

有人可以帮忙吗?

if(isset($_POST['order'])) 
{


//values to be inserted in database table
$order = $_POST['order']; #order
global $restaurant;
$request_time = date('H:i'); #request_time
$status = "requested"; #status
$date = date("m.d.y"); #date
$assigned_to = "";

$mysqli = new mysqli('localhost','foodcour_user','1020304050@','foodcour_db');
if ($mysqli->connect_error) {
die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error);
}

$query = "INSERT INTO products (product_code, product_name, price) VALUES(?, ?, ?)";
$query = "INSERT INTO 'deliverys' ('restaurant', 'order', 'request_time', 'status', 'date', 'assigned_to') VALUES ('?', '?', '?', '?', '?', '?')";
#$statement = $mysqli->prepare($query);
if( ! $statement = $mysqli->prepare($query) ) {
echo 'Error: ' . $mysqli->error;
return false; // throw exception, die(), exit, whatever...
} else {
//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('ssssss', $restaurant, $order, $request_time, $status, $date, $assigned_to);

if($statement->execute()){
print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />';
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
}

最佳答案

以下查询是错误的

    $query = "INSERT INTO 'deliverys' 
('restaurant', 'order', 'request_time', 'status', 'date', 'assigned_to')
VALUES ('?', '?', '?', '?', '?', '?')";

去掉列名和表名上的引号

order 是保留字,需要在后面打勾``

去掉 ? 上的单引号在绑定(bind)参数中

$query = "INSERT INTO deliverys 
(restaurant, `order`, request_time, status, date, assigned_to)
VALUES
(?, ?, ?, ?, ?, ?)";

关于mysql - 错误: You have an error in your SQL syntax INSERT with BIND PARAM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27880574/

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