gpt4 book ai didi

php - MySQL 错误 "an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near"

转载 作者:行者123 更新时间:2023-11-29 01:37:26 25 4
gpt4 key购买 nike

我在将数据插入数据库时​​从 MySQL 收到此错误:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'leave (apply_date, leave_category, leave_type, from_date, to_date, reason, duty_' at line 1"

我之前没有收到过(一个多星期前我做了同样的脚本,从来没有出现过这个错误。

下面是“func.php”文件的代码

function apply_leave($apply_date,$category,$type,$from,$to,$reason,$assign){

$result=mysql_query("INSERT INTO leave (apply_date, leave_category, leave_type, from_date, to_date, reason, duty_assign)
VALUES ('$apply_date', '$category', '$type', '$from', '$to', '$reason', '$assign')")or die("error on query".mysql_error());

下面是“leave_apply.php”文件的代码

if(isset($_POST['apply'])){
$apply_date=$_POST['apply_date'];
$category=$_POST['category'];
$type=$_POST['type'];
$from=$_POST['from'];
$to=$_POST['to'];
$no_of_date=$_POST['no_of_date'];
$reason=$_POST['reason'];
$assign=$_POST['assign'];
$result=apply_leave($apply_date, $category, $type, $from, $to, $reason, $assign);

最佳答案

leave 是一个 reserved keyword in MySQL需要用反引号转义。

INSERT INTO `leave` (...)

关于php - MySQL 错误 "an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37070357/

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