MySQL服务器版[关闭]

MySQL服务器版[关闭]

问题描述:

I have this problem, on my website i try to comment on a profile page, but when i click to submit it, it says

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, msg, author,time)
VALUES ('52', Test','Sakaio911', NOW())' at line 1

All I'm doing is inserting the comment into the database, and you can see what columns. Is it the NOW() that causes it because i have no idea what im doing wrong.

我有这个问题,在我的网站上我尝试评论个人资料页面,但是当我点击提交它 ,它说 p>

 你的SQL语法有错误; 检查与你的MySQL服务器版本相对应的手册,以便在第1行的“to,msg,author,time”附近使用正确的语法
VALUES('52',Test','Sakaio911',NOW())'  n  code>  pre> 
 
 

我正在做的就是将注释插入数据库,你可以看到哪些列。 它是NOW()导致它,因为我不知道我做错了什么。 p> div>

The error message points you to the 'to' column name. According to the documentation, that name is reserved as a key-word. You will probably want to rename that col, or you will have to do some gymnastics to use that table.

http://dev.mysql.com/doc/refman/5.0/en/reserved-words.html

Make sure you have a semicolon both for the sql query and the php code line itself.One semicolon inside the " " marks and the other outside to terminate the line of code.

Wrap the field names with back ticks ... so for example `to`,`msg` etc. That should solve that particular problem.

('52', Test','Sakaio911', NOW())'

The insert statement uses commas as delimiters for the field names and their values. It appears that you're missing something between the '52' and the Test'. Are you short a single quote before Test' or should the entire string be in double quotes like this? "This'".

When you don't want to rename your column name, you must escape it in context by `

 ... `to`, msg, author, time) VALUES ('52', 'Test','Sakaio911', NOW())