add.php文件中:<form action="add.php" method="post" >
  用户:<input type="text" name="user" size=10/><br>
  标题:<input type="text" name="title" /><br>
  内容:<textarea name="content"/></textarea><br>
  <input type="submit" name="submit" value="发表留言啦"/>
  </form>
<?php
 include("connect.php");
 if($_post['submit']){
  $sql="insert into message (id,user,title,content,lastdate)values('',$_post[user],$_post[title],$_post[content],now()";
  //$result=mysql_query($sql,$a)or die (mysql_error());
  mysql_query($sql);
  echo "succeed!";
 }else{
  echo "failed!";
 }?>connect.php文件中:
<?php
 $a= @ mysql_connect("localhost","root","")or die ("连接错误");
 mysql_select_db("newdb",$a);
 mysql_query("set names 'GBK'"); //用GBK中文编码
?>
为什么留言版不能提交数据到数据库newdb中呢?而且一开始还未在表单里写内容就出现了“failed!”谢谢解答!!!

解决方案 »

  1.   

    1,php变量名错了
    if($_post['submit']) $_POST要大写
    -->if($_POST['submit'])2.sql语句错了.
    =============================
    $sql="insert into message (id,user,title,content,lastdate)values('','{$_post['user']}','{$_post['title']}','{$_post['content']}',now())"; 
    一眼扫下来就两个错误,lz再好好检查下。
      

  2.   

    晕,sql语句中的$_post也要改成大写的$_POST
      

  3.   

    sql语句错在哪里啊,大侠!!?谢谢
      

  4.   

    大小写我已经改了,但是还是提交不了数据库,用mysql_error()函数显示了这样的错误:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,now()' at line 1
      

  5.   


    你的sql 语句没加''
    参考1楼所写的sql语句,把post 改成大写在试试
      

  6.   

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

  7.   

    代码高亮框把后面的给隐掉了,唠叨没发现lz最后那里漏了个 )
    $sql="insert into message (id,user,title,content,lastdate)values
    ('','{$_post['user']}','{$_post['title']}','{$_post['content']}',now())";
      

  8.   

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

  9.   

    代码应该这样的
    if($_POST['submit']){
    $sql="insert into message(id,user,title,content,lastdate)values" .
      "('','$_POST[user]','$_POST[title]','$_POST[content]',now())";
    mysql_query($sql); 
    echo "succeed!"; 
    }else{ 
    echo "failed!"; 

      

  10.   

    还有一个问题,为什么还未填写表单,就已经显示succeed呢?
      

  11.   

    这里写的不是很规范,你要测试是不是能显示表单,可以在$sql加个echo输出看看,这样先输出传过来表单的内容,在输出succeed
      

  12.   

    if($_POST['submit']){ 
    echo $sql="insert into message(id,user,title,content,lastdate)values" . 
    "('','$_POST[user]','$_POST[title]','$_POST[content]',now())"; 
    /*mysql_query($sql); 
    echo "succeed!"; 
    }else{ 
    echo "failed!"; */

     这样可以判定是否能接受post过来的内容了 
      

  13.   

    主要是sql语句内的变量如果不是数字型的话要加引号,另外POST需要定成大写的!