填完留言板 数据库中没有提交的数据怎么回事??
文件conn.php:
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); ?>文件add.php:<?php include("conn.php");
if($_POST[submit]){
$sql="insert into ted (id,user,title,content,lastdate) values ('','$_POST[user]'),'$_POST[title]','$_POST[content]'," .
"now()";
mysql_query($sql);
echo "发表成功!";
}
?>
<br /><hr/>
<form action="add.php" method="post">
用户名:
<input type="text" name="user" /><br/>
标题:
<input type="text" name="title" size="10" maxlength="40"/><br/>
内容:
<textarea name="content" >
</textarea><br/>
<hr/>
<input type="submit" name="submit" value="发布留言"/>
</form>
文件conn.php:
<?php
$conn = @ mysql_connect("localhost", "root", "") or die("数据库链接错误");
mysql_select_db("bbs", $conn);
mysql_query("set names 'GBK'"); ?>文件add.php:<?php include("conn.php");
if($_POST[submit]){
$sql="insert into ted (id,user,title,content,lastdate) values ('','$_POST[user]'),'$_POST[title]','$_POST[content]'," .
"now()";
mysql_query($sql);
echo "发表成功!";
}
?>
<br /><hr/>
<form action="add.php" method="post">
用户名:
<input type="text" name="user" /><br/>
标题:
<input type="text" name="title" size="10" maxlength="40"/><br/>
内容:
<textarea name="content" >
</textarea><br/>
<hr/>
<input type="submit" name="submit" value="发布留言"/>
</form>
"now()";
里面有一个),要把它写在后面
$sql="insert into ted (id,user,title,content,lastdate) values ('','$_POST[user]','$_POST[title]','$_POST[content]'," .
"now()");
"now()";
mysql_query($sql);
#改成
$sql="insert into ted (id,user,title,content,lastdate) values ('','".$_POST['user']."'),'".$_POST['title']."'," .
"'".$_POST['content']."',now()";
$res = mysql_query($sql);
if(!$res)
die("SQL:{$sql}<br>Error:".mysql_error());
if(mysql_affected_rows() > 0){
#while($rows = mysql_fetch_array($res,MYSQL_ASSOC)){
#
#}
}else{
echo "操作失败,Error:".mysql_error();
}