add.php 文件
<?php
/*
 * Created on 2011-12-27
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 include("conn.php"); if(isset($_POST['submit']) && $_POST['submit']){
$sql = "insert into message (id,user,title.content,lastdate) values ('','$_POST[user]','$_POST[title]',$_POST[content].now())";
mysql_query($sql);
  echo "<script language=\"javascript\">alert('添加成功');history.go(-1)</script>";
 }
 include("head.php");
?>
<script language="JavaScript">
function CheckPost()
{
if (myform.user.value=="")
{
alert("请填写用户名");
myform.user.focus();
return false;
}
if (myform.title.value.length<5)
{
alert("标题不能少于5个字符");
myform.title.focus();
return false;
}
if (myform.content.value=="")
{
alert("必须要填写留言内容");
myform.content.focus();
return false;
}
}</script>
<form action="add.php" method="post" name="myform" onsubmit="return CheckPost();">
  用户:<input type="text" size="10" name="user" /><br>
  标题:<input type="text" name="title" /><br/>
  内容:<textarea name="content"  cols="60" rows="9"></textarea><br/>  <input type="submit" name="submit" value="发布留言"/></form>
conn.php 文件
<?php
/*
 * Created on 2011-12-27
 *
 * To change the template for this generated file go to
 * Window - Preferences - PHPeclipse - PHP - Code Templates
 */
 $conn = @ mysql_connect("localhost","root","") or die("数据库错误"); // 连接数据库
 mysql_select_db("xuexi",$conn); //打开 xuexi 数据库
 mysql_query("set names 'GBK'"); //使用GBK 中文编码; // 替换编码
 function htmtocode($content){
  $content = str_replace("\n","<br>",str_replace(" ","&nbsp;",$content));
  return $content;
 }
?>

解决方案 »

  1.   

    mysql_query($sql) or die(mysql_error());
    看看都有什么
      

  2.   

    $sql = "insert into message (id,user,title.content,lastdate) values ('','$_POST[user]','$_POST[title]',$_POST[content]now())"
      

  3.   


    你的SQL语句有问题!首先id不能为空,第二 title和content之间应该是逗号,不是点!
    $sql = "insert into message (id,user,title,content,lastdate) values ('11','$_POST[user]','$_POST[title]',$_POST[content],now())"
    那个ID=11是我随便传的一个,现在你试试