Home > Database > Mysql Tutorial > body text

php insert id错误解决办法

WBOY
Release: 2016-06-07 17:50:56
Original
1259 people have browsed it

本人在开发中碰到的问题就是php insert 到数据库时insert不成功也不报任何错误。真是崩溃!

原始代码

 代码如下 复制代码

$sql="INSERT INTO `message` (`id`, `user`, `title`, `content`, `lastdate`) VALUES ('', '$_POST[user]', '$_POST[title]', '$_POST[content]', 'now()')";
_query($sql);


修改后代码

 代码如下 复制代码

$sql="INSERT INTO `message` (`user`, `title`, `content`, `lastdate`) VALUES ( '$_POST[user]', '$_POST[title]', '$_POST[content]', 'now()')";
mysql_query($sql);

去掉id,因为id是自动插入,所以去掉,这样就OK了!

如果字段是tinyint,int, ...类型的要么自动插入,要么给默认值,不要`id` values('')这样的空值,因为每个mysql版本不一样,会出现问题而找不出原因。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!