我通过php获得页面参数,组成一句sql语句如下:
insert into imgbook('id','author','title','desc','path') values (null,'dsrgsd','sfg','sdger','uploads/title.gif')在执行插入的时间总是报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio
for the right syntax to use near ''id','author','title','desc','path') values (null,'dsrgsd','sfg','sdger','upload' at
line 1
各位大虾指点迷津。
insert into imgbook('id','author','title','desc','path') values (null,'dsrgsd','sfg','sdger','uploads/title.gif')在执行插入的时间总是报错:ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server versio
for the right syntax to use near ''id','author','title','desc','path') values (null,'dsrgsd','sfg','sdger','upload' at
line 1
各位大虾指点迷津。
insert into imgbook(id,author,title,desc,path) values (null,'dsrgsd','sfg','sdger','uploads/title.gif')
数据库字段不要单引号!
刚才也去试了一下
mysql> insert into imgbook(id,author,title,desc,path) values (null,'tdfy54','dg54gf','rtdyg','uploads/title.gif');
ERROR 1064 (42000): 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 'desc,path) values (null,'tdfy54','dg54gf','rtdyg','uploads/title.gif')' at line 1
这个错了,插入的字段不是用(')单引号,用的是键盘TAB键上面的那个(`),代码改成insert into `imgbook`(`id`,`author`,`title`,`desc`,`path`) values (null,'dsrgsd','sfg','sdger','uploads/title.gif')
这样子一般就可以了,如果还不行就真有可能是数据类型问题了,建议把所以字段的类型都改成varchar(50),等测试通过再改回来!别忘记给分,我最近来自己就是为了分数
2 看看ID是不是自动增加
3 对“/”进行转意思再试试 即:insert into `contents`(`id`,`name`,`content`) values (null,'dsrgsd','uploads\/title.gif')
insert into imgbook values (null,'dsrgsd','sfg','sdger','uploads/title.gif')你这样试试 看看有没有什么提示?
为避免书写的不规范,最好的做法是缺省主键项
本身主键就是表示“唯一”,不具备任何实际意义