Home > Backend Development > PHP Tutorial > 大家来看这段代码,如何插不进数据库

大家来看这段代码,如何插不进数据库

WBOY
Release: 2016-06-13 13:06:52
Original
750 people have browsed it

大家来看这段代码,怎么插不进数据库
include("db.php");
if(!empty($_POST['sub'])){
$title=$_POST['title'];
$con=$_POST['non'];
$sql="insert into `test` (`id`,`title`,`non`,`date`) VALUES('null','$title','$con',now())";
mysql_query($sql);
echo "插入成功";
 }
 
?>



<br>news-add<br>

 

标题:

内容:






------解决方案--------------------
$sql="insert into `test` (`id`,`title`,`non`,`date`) VALUES('null','$title','$con',now())";
我想你数据库test表的id是整形吧? 'null' 会被理解为四个字节的字符串 null ,而不是类型上的空。
而且id也应该是递增字段,所以不需要赋值也可以的:
PHP code
$sql="insert into `test` (`title`,`non`,`date`) VALUES('$title','$con', now())"; <div class="clear">
                 
              
              
        
            </div>
Copy after login
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