为什么我不能将数据插入mysql服务器?

时间:2011-06-25 20:31:38

标签: php mysql

我有2个脚本可以将我网站上的内容记录到mysql数据库中。它们都在同一台服务器上使用相同的数据库,唯一的区别是表。我用来插入值的代码如下所示:

INSERT INTO table(full_name, email_address, phone_number, message, ip_address, agent)
VALUES ('$fn', '$email', '$telephone', '$comments', '$ip', '$agent')

有谁能告诉我为什么一个脚本会起作用而另一个脚本不起作用?

2 个答案:

答案 0 :(得分:3)

错误几乎总是恰好出现在错误消息中'开始的位置。看起来你正在插入一个名为log的表,虽然我不认为它是一个保留的MySQL关键字,你可以尝试用反引号引用表名并在左括号前加一个空格:

INSERT INTO `log` (tm, ref, agent, ip, page) VALUES (....);

UPDATE LOG()不是关键字,但它是MySQL数字函数。由于你在括号旁边使用它,MySQL可能会将其解释为错误的函数调用。 http://dev.mysql.com/doc/refman/5.0/en/numeric-functions.html

答案 1 :(得分:0)

尝试使用mysql_error()检查错误。

mysql_query("INSERT INTO table(
         full_name, email_address, phone_number, message, ip_address, agent) 
         VALUES ('$fn', '$email', '$telephone', '$comments', '$ip', '$agent')")
         or die(mysql_error());
相关问题