<?php
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 "插入成功";
}
?><html>
<head>
<title>
news-add
</title>
</html>
<body>
<form action="first.php" method="post">
标题:<input type="text" name="title" /> <br />
内容:<textarea name="non" cols="100" rows="5"></textarea><br />
<input type="submit" name="sub" value="发布" />
</form>
</body>
</html>
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 "插入成功";
}
?><html>
<head>
<title>
news-add
</title>
</html>
<body>
<form action="first.php" method="post">
标题:<input type="text" name="title" /> <br />
内容:<textarea name="non" cols="100" rows="5"></textarea><br />
<input type="submit" name="sub" value="发布" />
</form>
</body>
</html>
我想你数据库test表的id是整形吧? 'null' 会被理解为四个字节的字符串 null ,而不是类型上的空。
而且id也应该是递增字段,所以不需要赋值也可以的:
$sql="insert into `test` (`title`,`non`,`date`) VALUES('$title','$con', now())";
后面的now()是什么函数?如果用time()的话,改成
$sql="insert into `test` (`title`,`non`,`date`) VALUES('$title','$con','time()')";推荐把这条语句写成
$sql="insert into `test `(`title`,`non`,`date`) VALUES('{$title}','{$con}','{time()}')";如果仍然找不到错误,我有个建议:
echo $sql;
你在打开这个页面的时候肯定echo 出来的字符串,你看下什么地方不对,如果看不出来,就拿到phpMyAdmin里,执行一下.