MySQL语法错误 - 额外的眼睛?

时间:2011-10-17 11:15:40

标签: mysql sql syntax

有人可以盯着这句话吗?我不断收到语法错误,我对这出错是多么难过。

mysql_query("INSERT INTO emails (to, from, subject, content, ip) VALUES('$email_to', '$email_from', '$subject', '$content', '$ip' ) ") 

谢谢!

编辑:错误

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 ''to', 'from', subject, content, ip) VALUES('[MY EMAIL ADDRESS]', 'l', 'hi', ' at line 1

编辑2:

我已经消毒了。

$email_to = mysql_real_escape_string($_POST['email_to']);
$email_from = mysql_real_escape_string($_POST['email_from']);
$subject = mysql_real_escape_string($_POST['subject']);
$content = mysql_real_escape_string($_POST['content']);

2 个答案:

答案 0 :(得分:4)

试试这个:

mysql_query(
    "INSERT INTO emails (`to`, `from`, subject, content, ip) 
    VALUES('$email_to', '$email_from', '$subject', '$content', '$ip' )") 

我认为错误会引发,因为from是一个保留字...反引号应该可以解决这个问题 请记住,必须始终清理用户输入以避免SQL注入!!

答案 1 :(得分:1)

也许逃避'from'字段,因为from是关键字;