<html>
<head>
<title>留言本</title>
</head>
 <body>
 <?php
 if($_post['submit'])
 {
    $name=$_post['name'];
    $time=getdate();
    $txt=$_post['txt'];
    $conn=mysql_connect("localhost","root","123")or die ("can't connect to mysql");
    $qurry="insert into tb(name,time,txt) values ('$name','$time','$txt')";
    //$qurry = "select *from tb";
    $result= mysql_db_query("test",$qurry);
    //$row=mysql_fetch_row($result);
    //print_r($row);
 }
 else 
 {
 ?>
   <form action="<?php echo$PATH_INFO;?>" method="post" >
    姓名:<input type="text" name="name"><br>
    留言:<textarea name="txt" rows="10" cols="50">
    </textarea>
    <input type="reset" value="清除">
    <input type="submit" name="submit" value="留言提交">
   </form>
<?php
 }
?>
 </body>
</html>上面为什么我点"留言提交" 这个按钮  数据库没反应?是POST没传值还是 我那边写错了? 
刚学PHP 希望高手指正!

解决方案 »

  1.   

    echo $query;
    然后在mysql执行看行不行
      

  2.   

    大哥! 没执行!好像根本就没指定到这个页面上? 是不是我form写的有问题?
      

  3.   

    把$_post['submit'] 改为$_POST['submit']因为你的 if($_post['submit']) 不成立 所以一直显示的是表单
      

  4.   

      <form action="这里改为你文件的文件名" method="post" >$_post==>$_POST要大写
      

  5.   


    Create table (
    id int not null auto_increment,
    name char(8) not null,
    time datetime not null,
    txt varchar(5000) not null,
    primary  key (id)
    )数据库结构这样
    运行时没报错!
      

  6.   

    Create table tb(
    id int not null auto_increment,
    name char(8) not null,
    time datetime not null,
    txt varchar(5000) not null,
    primary  key (id)
    )
      

  7.   

    pirnt_r($_POST)看下传的值是否有空值
    数据库字段为 not null 不允许为空另外在数据库中 手动执行下 insert into tb(name,time,txt) values ('Discounts','2009-10-26 00:00:00','http://www.discountsinchina.com');
      

  8.   

    大哥 数据库绝对没问题!这个放心,主要是我对PH form 传值搞不清。
    我查了一下 有好几种写法
    1.<form action="<?php echo$PATH_INFO;?>" method="post" >
    2.<form action="<?php echo $_SERVER["PATH_SELF"];?>" method="post" >
    3.<form action="<?php echo $PATH_SELF;?>" method="post" >
    哎!以前是学ASP.NET。现在搞PHP了
      

  9.   

    <form action="<?php echo$PATH_INFO;?>" method="post" >
     改成<form method="post" >
      

  10.   

    取得本页地址 应该用 2. <form action="<?php echo $_SERVER["PATH_SELF"];?>" method="post" > 
    或则
    <form action='' method='POST'> 也可以传到本页!
      

  11.   

    按照你写的我改了一下,能插进去了 你看看把<html>
    <head>
    <title>留言本</title>
    </head>
     <body>
     <?php
     if($_POST['submit'])
     {
        $name=$_POST['name'];
        $time=date("Y-m-d H:i:s");
        $txt=$_POST['txt'];
        $conn=mysql_connect("localhost","root","123")or die ("can't connect to mysql");
        $qurry="insert into tb(name,time,txt) values ('$name','$time','$txt')";
        //$qurry = "select *from tb";
        $result= mysql_db_query("test",$qurry);
        //$row=mysql_fetch_row($result);
        //print_r($row);
     }
     else
     {
     ?>
       <form action="<?php echo $PATH_INFO;?>" method="post" >
        姓名:<input type="text" name="name"><br>
        留言:<textarea name="txt" rows="10" cols="50">
        </textarea>
        <input type="reset" value="清除">
        <input type="submit" name="submit" value="留言提交">
       </form>
    <?php
     }
    ?>
    </body>
    </html>
      

  12.   

    能否报上大名 干吗老用悠嘻猴额 很像在下的风格哦这样吧 你把die 改成mysql_error()看看有没有爆出错误,把错误赋值给大家看 if($_POST['submit'])
     {
        $name=$_POST['name'];
        $time=date("Y-m-d H:i:s");
        $txt=$_POST['txt'];
        $conn=mysql_connect("localhost","root","123")or die (mysql_error()."不能连接mysql");
        $qurry="insert into tb(name,time,txt) values ('$name','$time','$txt')";
        //$qurry = "select *from tb";
        $result= mysql_db_query("test",$qurry) or die (mysql_error()."不能连接mysql");
        //$row=mysql_fetch_row($result);
        //print_r($row);
     }
     else
     {
     ?> 
      

  13.   


    再问一下 $PATH_INFO 这应该是个链接赋给这个变量了吧 你有这个连接的页面吗?!是本页?还是... 
      

  14.   

    如果没记错,在本页处理表单,把表单的action属性去掉也可以吧?O(∩_∩)O~
    提交的值对不对把 $_POST打印出来就看到了~~~~~~~
    var_dump($_POST);