<?php require("bbshead.php")?> <div id="bt">写留言<hr /></div>
<div id="bd">
<form mothod="post" action="<?php echo "$_SERVER[PHP_SELF]";?>">
<table width="100%" border="0" cellspacing="0" class="td1">
<tr>
  <td align="right">&nbsp;昵&nbsp;称:</td>
<td><input name="name" type="text" size="20" maxlength="20"></td>
<td align="right">Email:</td>
<td><input name="email" type="text" size="22" maxlength="20"></td>
</tr>
<tr>
<td align="right">&nbsp;主&nbsp;题:</td>
<td colspan="3"><input name="btitle" type="text" size="80" maxlength="80"/></td>
</tr>
<tr>
<td align="right">&nbsp;内&nbsp;容:</td>
<td colspan="3"><textarea name="msg" cols="95" rows="8"></textarea></td>
</tr>
<tr>
<td align="center" colspan="4"><input type="submit" name="action" value="写好了">
<input type="reset" value="重写"><input type="submit" name="action" value="放弃"</td>
</tr>
</table>
</form>
</div>
<?php 
if($action=="放弃")
echo "<meta http-equiv='Refresh' content='0;url=bbsindex.php'>";
else if($action=="写好了"){
if($name!="" && $email!="" && $msg!="" && $btitle!=""){
include_once("sys_conf.inc");
//建立与Mysql数据库连接
$connection=mysql_connect($DBHOST,$DBUSER,$DBPWD) or die("无法连接数数据库!");
print "$DBHOST";
mysql_query("set names 'utf-8'");//设置字符集
mysql_select_db("guest") or die ("无法连接数据库!");
//向服务器发送查询请求
$query="insert into guestlist(name,btime,msg,email,btitle) values('$name',now(),'$msg','$email','$btitle')";
$result=mysql_query($query,$connection) or die("存入数据库失败!");
mysql_close($connection) or die("无法断开与数据库的连接!");
$err="填写留言成功!<br />2秒后自动返回。\n";
echo "<meta http-equiv=\"Refresh\" content=\"2; url=bbsindex.php\">";
}
else{
$err="出错了!\n信息不全!昵称、邮箱、主题和内容是必须填写的!\n";
echo "<meta http-equiv=\"Refresh\" content=\"2; url=$_SERVER[PHP_SELF]\">";
}
}
?>
<div id="err" align="center"><?php echo $err;?></div><!--提示信息显示区-->
<hr />
<!--使用<iframe>标记加载bbsbottom.html-->
<iframe scrolling="no" width="780" height="60" src="bbsbottom.html" marginwidth="0" marginheight="0" border="0" frameborder="0" align="center">不支持</iframe>
</div> <!--与bbshead中的<div id="app">对应-->
</body>
</html>

解决方案 »

  1.   

    $action 要写作 $_POST['action']
      

  2.   


    把表单的内容通过POST传到PHP中处理。        
                      <?php
         29                 $action=$_POST['action'];  
         30                 if($action=="放弃")
         31                         echo "<meta http-equiv='Refresh' content='0;url=bbsindex.php'>";
         32           ?>
    但是还是没用啊,到底是什么原因?