MySQL中的SQL语法错误 [英] SQL syntax error in mysql

查看:203
本文介绍了MySQL中的SQL语法错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将值从php插入到我的MySQL表中:

I'm inserting value to my MySQL table from php as:

$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时,我得到的输出为:

on trying echo for $sql I'm getting output as:

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'

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

but I'm continuously getting the same error message:

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对于这种可怕的错误没有给出适当的错误?

even if I try to remove ' around the values of column names.
I'm using the same syntax for inserting data and that's working fine.
What's wrong with this?
Why MySQL does not give a proper error for such terrible mistake?

推荐答案

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

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

FROM is reserved word use backtick around it.

这篇关于MySQL中的SQL语法错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆