小编典典

MySQL中的SQL语法错误

sql

我正在从以下位置向我的MySQL表插入值php

$journey = $_POST['way'];
$from = $_POST['from'];
$to = $_POST['to'];
$dpdt = $_POST['dp_date'];
$rtdt = $_POST['rt_date'];
$fare = $_POST['fare'];
$sql = "insert into tours set " .
        "journey='$journey', from='$from', to='$to', dp_date=CAST('$dpdt' AS DATE), " .
        "rt_date=CAST('$rtdt' AS DATE), fare='$fare'";

尝试echo$sql我得到的输出为:

insert into tours set journey='round', from='Aurangabad', to='Kashmir', dp_date=CAST('27-08-2013' AS DATE), rt_date=CAST('21-08-2013' AS DATE), fare='2500'

但我不断收到相同的错误消息:

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 'from=Aurangabad, to='Kashmir', dp_date=CAST('27-08-2013' AS DATE), rt_date=CAST(' at line 1

即使我尝试删除'列名的值。
我使用相同的语法插入数据,并且工作正常。
这怎么了
为什么MySQL对于这种可怕的错误没有给出适当的错误?


阅读 179

收藏
2021-04-15

共1个答案

小编典典

`from`='$from', `to`='$to'

FROM 是保留字,请在其周围使用反引号。

2021-04-15