我正在从以下位置向我的MySQL表插入值php:
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我得到的输出为:
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对于这种可怕的错误没有给出适当的错误?
'
`from`='$from', `to`='$to'
FROM 是保留字,请在其周围使用反引号。
FROM