mysql无法写入数据
$conn=mysql_connect("localhost","root","")ordie("数据库打开错误");mysql_select_db("bbs",$con...
$conn=mysql_connect("localhost","root","")or die("数据库打开错误");
mysql_select_db("bbs",$conn)or die("数据库连接错误");
mysql_query("set names 'GBK'");
--------------------------------------------
include("conn.php");
if($_POST['submit']){
$sql="INSERT INTO yizhuren (id,user,title,content,lastdate) " .
"values('id','$_POST[user]','$_POST[title]','$_POST[content]'now())";
mysql_query($sql);
echo "发布成功";
}
?>
<form action="add.php" method="post">
用户:<input type="text" sise="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:
<textarea name="content">
</textarea><br/>
<input type="submit" name="submit" value="发布留言"/>
网页显示发布成功,但数据库里没有数据 展开
mysql_select_db("bbs",$conn)or die("数据库连接错误");
mysql_query("set names 'GBK'");
--------------------------------------------
include("conn.php");
if($_POST['submit']){
$sql="INSERT INTO yizhuren (id,user,title,content,lastdate) " .
"values('id','$_POST[user]','$_POST[title]','$_POST[content]'now())";
mysql_query($sql);
echo "发布成功";
}
?>
<form action="add.php" method="post">
用户:<input type="text" sise="10" name="user" /><br>
标题:<input type="text" name="title" /><br/>
内容:
<textarea name="content">
</textarea><br/>
<input type="submit" name="submit" value="发布留言"/>
网页显示发布成功,但数据库里没有数据 展开
1个回答
2013-08-01
展开全部
你的
$sql="INSERT INTO yizhuren (id,user,title,content,lastdate) " .
"values('id','$_POST[user]','$_POST[title]','$_POST[content]'now())";
这句不对
应该这样
$user = $_POST[user];
$title = $_POST[title];
$content = $_POST[content];
$now = now();
$sql="INSERT INTO yizhuren (id,user,title,content,lastdate) values('id','$user','$title','$content','$now')";
$sql="INSERT INTO yizhuren (id,user,title,content,lastdate) " .
"values('id','$_POST[user]','$_POST[title]','$_POST[content]'now())";
这句不对
应该这样
$user = $_POST[user];
$title = $_POST[title];
$content = $_POST[content];
$now = now();
$sql="INSERT INTO yizhuren (id,user,title,content,lastdate) values('id','$user','$title','$content','$now')";
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询