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呢?
不过上面的代码没出现,还没到那就直接判断失败了.
新来,只有这么多分...还望不吝赐教.
//提交后地址显示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呢?
不过上面的代码没出现,还没到那就直接判断失败了.
新来,只有这么多分...还望不吝赐教.
没有了,我把第二部分那堆sql的删了之后,仍然进入else,但是就写不进数据库了.
<?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删了数据库也写不进去了
提交后显示的这个localhost/viewentry.php?id=1
print_r($_POST); //贴出结果