开发者

Why can't I insert data into mysql server?

I have 2 scripts that log things on my website to a mysql database. They both use the same database on the same server, with the only difference being the table. The code i am using to insert values looks like this:

INSERT INTO table(full_name, email_address, phone_number, messa开发者_如何学编程ge, ip_address, agent)
VALUES ('$fn', '$email', '$telephone', '$comments', '$ip', '$agent')

Can anyone tell me why one script will work and the other will not?


The error nearly always occurs exactly where the ' starts in the error message. Looks like you're inserting into a table called log and although I didn't think it's a reserved MySQL keyword, you might try quoting the table name with backquotes and putting a space before the opening parenthesis:

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

UPDATE LOG() isn't a keyword, but it is a MySQL numeric function. And since you're using it right beside parentheses, MySQL is likely interpreting this as a faulty function call. http://dev.mysql.com/doc/refman/5.0/en/numeric-functions.html


Try using mysql_error() to check for errors.

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());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜