我有一个表单 method = post 提交到表单处理程序文件,该文件将帖子写入数据库,然后通过电子邮件将结果发送给用户。
我已经编写了一个插入语句,但是在处理表单时出现错误,但我不是 DB 高手,我不确定问题出在哪里。这是代码--
// MYSQL QUERY
$result = mysql_query("INSERT INTO 2009_prize_results
(name, address, address2, email, 100, 101, 102, 103, 104, 105, 106, 107, 108)
VALUES
($_POST[name],$_POST[address],$_POST[address2],$_POST[email]
,$_POST[100],$_POST[101],$_POST[102],$_POST[103],$_POST[104],$_POST[105]
,$_POST[106],$_POST[107],$_POST[108])");
if (!$result) {
die ("SQL error: " . mysql_error());
}
我得到的错误是——
SQL error: 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 '100, 101, 102, 103, 104, 105, 106, 107, 108) VALUES (Marty Martin,313 Orlando Av' at line 1
提交值是
name = Marty Martin
address = 313 Orlando Ave
address2 = Anytown, VA
email = foo@foo.com
100 = on
101 = off
10* are all checkboxes so are either on or off
我这里有什么问题吗?
最佳答案
请看:
How does the SQL injection from the "Bobby Tables" XKCD comic work?
如果您必须使用 mysql 库,那么请确保您正在通过 mysql_real_escape_string 运行所有输入,否则使用准备好的语句。
然后,当您将查询放在一起时,将所有 VALUES 括在引号中(单引号或双引号都可以)。
关于php - php mysql查询的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/596552/