index.php中表单部分<form action="<?php echo "viewentry.php?id=".$row['id'];?>" method="post">
//提交后地址显示localhost/viewentry.php?id=1
<table>
<tr>
<td> Name</td>
<td style="text-align:left"><input type="text" name="name"></td>
</tr>
<tr>
<td> Comment</td>
<td><textarea name="comment" rows="10" cols="50"></textarea></td>
</tr>
<tr>
<td style="text-align:left"><input type="submit" name="submit" value="add comment"/></td>
</tr>
</table>
</form>
提交位置viewentry.php部分<?php
require("config.php");
if($_POST){
       if(isset($_POST["submit"])){
       if(is_numeric($_GET['id'])){
$validentry=$_GET['id'];
$db=mysql_connect($dbhost,$dbuser,$dbpassword);
mysql_select_db($dbdatabase,$db);
$sql="insert into comments(blog_id,dateposted,name,comment) values(".$validentry.", now(), '".$_POST['name']."','".$_POST['comment']."');";
mysql_query($sql);
header("Location:http://localhost/viewentry.php?id=".$validentry);
require("header.php");
echo"<br><br>Input Successful";
echo"<br><a href=http://localhost/index.php>click here to get back</a>";
}
else{header("Location:".$config_basedir);}
}
else{echo "Null Submit.";}
}
else{echo "Null input.";}

?>
在我乱改的过程中也出现过undefined index: submit这种错误.我觉得提交了submit啊,为什么说没找到submit呢?
不过上面的代码没出现,还没到那就直接判断失败了.
新来,只有这么多分...还望不吝赐教.

解决方案 »

  1.   

    既然进入最后else 了,不可能还能写入数据库。除非你还有其他代码在执行。
      

  2.   

    开头就直接if(isset($_POST["submit"])){好了
      

  3.   


    没有了,我把第二部分那堆sql的删了之后,仍然进入else,但是就写不进数据库了.
      

  4.   

    哪个else ? 把你改过之后的代码贴出来。
      

  5.   


    <?php
    require("config.php");
    if(isset($_POST["submit"])){
    if(is_numeric($_GET['id'])){
    $validentry=$_GET['id'];
    header("Location:http://localhost/viewentry.php?id=".$validentry);
    require("header.php");
    echo"<br><br>Input Successful";
    echo"<br><a href=http://localhost/index.php>click here to get back</a>";
    }
    else{header("Location:".$config_basedir);}
    }
    else{echo "Null Submit.";}
    ?>这回输出null submit了.这儿sql删了数据库也写不进去了
      

  6.   

    要提交表单才会有 $_POST["submit"] 值。你提交表单了吗? 
      

  7.   

    我在第一个form那个页面提交的.
    提交后显示的这个localhost/viewentry.php?id=1
      

  8.   

    在 viewentry.php 文件加上: 
    print_r($_POST);  //贴出结果
      

  9.   

    先感谢一下,post没结果,我修改一下...
      

  10.   

    但问题是我输入的数据竟然能按照sql语句插入数据库,这是怎么回事.他是怎么跳出if直接进数据库的呢...