有人可以仔细检查一下这个声明吗?我不断收到语法错误,我很困惑到底出了什么问题。
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:
我已经 sanitizer 了。
$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']);
最佳答案
试试这个:
mysql_query(
"INSERT INTO emails (`to`, `from`, subject, content, ip)
VALUES('$email_to', '$email_from', '$subject', '$content', '$ip' )")
我认为错误的产生是因为 from
是一个保留字……反引号应该可以解决这个问题。
请记住,您必须始终清理用户输入以避免 SQL 注入(inject)!!
关于MySQL 语法错误 - 额外的眼睛?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7792948/