douhao8456 2009-02-27 20:30
浏览 17
已采纳

php mysql查询的问题

I have a form with method = post submitting to a form handler file which is writing the post to a DB and then emailing the result to a user.

I have written an insert statement but when the form is being processed I'm getting an error, but not being a DB whiz I'm not really sure what the problem is. Here's the code--

// 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());
}

And the error I'm getting is--

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

The submission values were

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

What do I have wrong here?

  • 写回答

6条回答 默认 最新

  • duanlv1366 2009-02-27 20:34
    关注

    you need single quotes around each item in VALUES

    EDIT: also your $_POST[] variables might not evaluate while in a string. You need to use a different syntax or use the evil extract();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值