<a href ='index.php' >返回留言板</a><hr><hr><?php/* * To change the template for this generated file go to * Window - Preferences - PHPeclipse - PHP - Code Templates */require("conn.php"); $user=$_POST['user']; $title=$_POST['title'];$content=$_POST['content'];$sql_luck="insert into sny (id,user,title,content,lastDate)value('','$user','$title','$content',now())";  $sql="SELECT user FROM sny WHERE user='$user'"; $query =mysql_query($sql); $rows=mysql_fetch_array($query);if((!empty($_POST['sub']))and($rows['user']==$user)){//echo $content;  echo "<script>alert('用户已存在,请重新输入');location.href='add2.php'</script>" ;exit;      mysql_free_result($query);exit; } else{  mysql_query($sql_luck);    echo"<script>alert('哟!成功!');location.href='index.php'</script>";    echo "插入成功"; }   ?><form action="add.php" method="post">用户:<input type="text" name="user" value="请输入用户名" size="20" maxlength="10"/><br/>标题:<input type="text" name="title" value="请输入内容" size="40" maxlength="40"/><br/>内容:<textarea name="content" rows="10" cols="50" wrap="off">text</textarea>   <br/>   <input type="submit" name="sub" value="Release"/><br/>   <form/>

解决方案 »

  1.   

    user 属于数据库关键字 `user`
      

  2.   

    1、在没有确认是POST提交方式之前,贸然使用$_POST,出错的概率90%
    2、对自增字段赋空字符,出错的概率50%
      

  3.   

    楼上的,楼主有确认是 method=“post”报什么错没?mysql_error();输出看看
      

  4.   

    php 里面能用and吗还是用&&符号吧。?
      

  5.   

    把sql,echo出来单独上数据库执行,字段类型。insert时候注意单引号变量insert into sny (TITLE,)value('".$TITLE."')
      

  6.   

    SQL语句执行是没问题的。但可能逻辑有问题。总是会莫名其妙的输入空值
      

  7.   

    $sql_luck="insert into sny (id,user,title,content,lastDate)value(null,'$user','$title','$content',now())";