報(bào)錯(cuò)1QLSTATE[42000]: Syntax error or access violation: 1064 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, to, name, subject, message) VALUES ('abc@gmail.com', 'lala@me.com' at line 1
使用
PDO
語(yǔ)法谎替,一組值是
$vals = array(
':from'=>$email,
':to'=>$recipient,
':name'=>$name,
':subject'=>$subject,
':message'=>$message
);
但是報(bào)錯(cuò)check the manual that corresponds to your MySQL server version for the right syntax to use near 'from, to, name, subject, message)
解決方式
from是SQL中的關(guān)鍵字裂逐。您不得將其用作列名稱而不引用它丧没。
在MySQL中,使用反引號(hào)引用列名稱抖僵,例如`from`
注意,是反引號(hào),而不是引號(hào) `Set`=:Set,
就個(gè)人而言狗唉,最好還是重命名列比較方便。
報(bào)錯(cuò)2[42S22][1054] Unknown column 'xi' in 'field list'
這是因?yàn)閤i作為一個(gè)值涡真,與字段應(yīng)有的值不匹配分俯。注意此處xi是值,而不是字段哆料。比如他是username
的值缸剪,解決方式是將xi
添加引號(hào)即可