以下是我的代码:
<?php
$conn =  mysql_connect("localhost", "root", "panpan") or die("数据库链接错误");
mysql_select_db("bba", $conn);
mysql_query("set names utf-8"); //使用GBK中文编码;if($_POST['submit']){
  $sql="insert into massge(user,title) " .
   "values('$_POST[user]','$_POST[title]')";
   $query=mysql_query($sql);
   if($query){
   echo "发表不能成功";
   }else {
   echo "插入失败";
   }
   
 }
mysql_close($conn);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<form id="form1" name="form1" method="post" action="add.php">
  <p>
    <label>用户:
      <input type="text" name="user" id="user" />
    </label>
  </p>
  <p>
    <label>标题:
      <input type="text" name="title" id="title" />
    </label>
  </p>
  <p>
    <label>
      <input type="submit" name="submit" id="submit" value="提交" />
    </label>
  </p>
</form>
</body>
</html>

解决方案 »

  1.   

    把SQL输出来看看 什么问题
    还可以把 mysql_error输出来看看
      

  2.   

    打开错误提示吧,这个错误提示会很清晰的告诉你是哪里有问题了.将SQL 到命令行下执行一下.
      

  3.   

    把插入语句换成 $sql="insert into massge(user,title) values('$_POST['user']','$_POST['title']')";
      

  4.   

    可以插入,我刚用你的代码试过了。你不会是把你贴出来的代码写在一个php文件中了吧?要分开写,上面的php代码写在“add.php”中,下面的html代码写在一个html文件里就行了
      

  5.   

    $sql="insert into massge(user,title) " .
       "values('$_POST[user]','$_POST[title]')";
       $query=mysql_query($sql);
    这句中得标红部分是不是该这么写:
    $sql="insert into massage(user,title) " .
       "values('$_POST[user]','$_POST[title]')";
       $query=mysql_query($sql);
      

  6.   

    遇到这样的问题,最先想到的是,直接打印sql,输出的sql放到编辑器,看运行情况~~
      

  7.   

    打钱SQL语句直接放到数据库里面运行一下,应该就能知道错误在哪了