php怎么设置只提交一次,并且点击提交后,跳转页面 phpmysql数据 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 PHP设置只提交一次便跳转其他页面示例//添加数据页面<form action="empProcess.php" method="post"><table><tr><td>名字</td><td><input type="text" name="name"/></td></tr><tr><td>级别</td><td><input type="text" name="grade"/></td></tr><tr><td>邮电</td><td><input type="text" name="email"/></td></tr><tr><td>薪水</td><td><input type="text" name="salary"/></td></tr><input type="hidden" name="flag" value="addemp"/><tr><td><input type="submit" value="添加用户"/></td><td><input type="reset" value="从新填写"/></td></tr></table></form>//处理添加数据页面并跳转<?phprequire_once 'common/EmpService.class.php';$empService=new EmpService();if(!empty($_REQUEST['flag'])){ $flag=$_REQUEST['flag']; if($flag=="del"){ $id=$_GET['id']; //echo "删除用户的id=$id"; if($empService->delEmpById($id)==1){ header("Location: ok.php"); exit(); }else{ header("Location: error.php"); exit(); }//codego.net/tags/4/1/ }else if($flag=="addemp"){ $name=$_POST['name']; $grade=$_POST['grade']; $email=$_POST['email']; $salary=$_POST['salary']; $res=$empService->addEmp($name,$grade,$email,$salary); if($res==1){ header("Location: ok.php"); exit(); }else{ header("Location: error.php"); } }else if($flag==updateemp){ $id=$_POST['id']; $name=$_POST['name']; $grade=$_POST['grade']; $email=$_POST['email']; $salary=$_POST['salary']; $res=$empService->updateEmp($id,$name,$grade,$email,$salary); if($res==1){ header("Location: ok.php"); exit(); }else{ header("Location: error.php"); } }}?>//如果成功跳转到OK页面<?php echo "恭喜你操作成功<br/>"; echo "<a href='empManage.php'>返回主界面</a>";?>//这里只提供添加数据后页面跳转(数据库分层操作略) 1.用户提交之后,按钮灰选状态。2.跳转有很多方法,具体是看服务端还是客户端方法,参考:header("Location:xx.php");echo "<script>alert('操作成功');location.href='xx.php';</script>"; location.header("refresh:5;url=../biaodan/cx_wdksm.php"); 提交两次是不是这句的原因 屏蔽试试 <form action="" method="post" name="form1" class="j" id="form1" onsubmit="submit_function(); return false;">关键在这个return false;上,告诉提交处理js函数是submit_function();之后不进行操作。 有个思路,再查询一次数据库,存在数据就用header,我目前就这样用…… 打开页面5秒后自动跳转了,是因为下面这句。location.header("refresh:5;url=../biaodan/cx_wdksm.php");改成这样就可以了,有提交才入库。入库后跳转。<?php if($_POST['send']=="true"){ mysql_query('INSERT INTO wdksm (time,name,mendian,bumen,zhiwu,wdktime,wdkyy,bmshtime,rsshtime) VALUES( \'' . $shijian . '\' , \'' . $conuser['xingming'] . '\' , \'' . $conuser['mendian'] . '\' , \'' . $conuser['bumen'] . '\' , \'' . $conuser['zhiwei'] . '\' , \'' . $_POST['textfield'] . '\' , \'' . $_POST['原因2'] . '\' , \'' . $_POST[''] . '\' , \'' . $conuser[''] . '\' )'); location.header("refresh:5;url=../biaodan/cx_wdksm.php"); }else{?><div id="syzf" style="text-align:center;"><div id="syzz" position:absolute;left:20%;width:94%;border-collapse:collapse;><br /><h1 align="center">新增未打卡说明</h1> <form action="" method="post" name="form1" class="j" id="form1"> 日期:<?php echo $shijian = date("Y-m-d G:i ",mktime()); ?> <table width="633" height="151" border="1" align="center" cellpadding="1" cellspacing="1"> <tr></tr><tr> <th width="100" scope="col" style="height:30px;width:100px;">部门 </th> <th width="100" scope="col"><?php echo $conuser['bumen'].''?> <th width="100" scope="col">姓名</th> <th width="100" scope="col"><?php echo $conuser['xingming'].'' ?> <th width="100" scope="col">职务</th> <th width="100" scope="col"><?php echo $conuser['zhiwei'].'' ?><tr> <th scope="row" style="height:30px;width:150px;">未打卡时间</th> <td colspan="5"><label for="textfield"></label> <input name="textfield" type="text" id="textfield" value="" style="height:30px;width:400px;"/></td></tr><tr> <th height="46" scope="row" style="height:30px;width:100px;">未打卡原因</th> <td colspan="5"><input name="原因2" type="text" id="原因" value="" style="height:30px;width:400px;"/> </tr><tr> <th height="30" colspan="2" scope="row">部门责任人审批</th> <td> </td> <td height="30" colspan="2" class="字体" scope="row">人事行政部/总经理审批</td> <td> </td></tr></table><tr><td height="30" align="center"> <input type="submit" id="hotKeyButton" name="Submit" value="提交" style="width:100px;height:35px;" /> <input type="reset" name="Reset" value="重置" style="width:100px;height:35px;" /></td></tr> <input type="hidden" name="send" value="true"></form><?php}?> 从服务器端上解决吧,提交页面生成一个SESSION,提交后接受一次数据,并删除这个SESSION,再提交校验SESSION值,如果不存在就不执行./ * 1、产生token,并存在session中 * 2、随页面生成 * 3、提交页面与session进行比对,成功后对session进行销毁 * 4、第二次提交则不存在这个值而报错 * @param type $uniqueid * @return type */ function createToken($uniqueid) { $uniqueid = empty($uniqueid) ? Yii::app()->user->id . Yii::app()->user->name . Yii::app()->user->mihome : $uniqueid; $token = md5("wms_check2_repeat" . $uniqueid); $_SESSION['form_token'] = $token; session_write_close(); return $token; } function checkToken($token) { if (!isset($_SESSION['form_token']) || empty($_SESSION['form_token']) || $_SESSION['form_token'] != $token) { return false; } else { unset($_SESSION['form_token']); return true; } } location.header("refresh:5;url=../biaodan/cx_wdksm.php"); php中odbc,adodb,ado,pdo连接数据库,他们有什么区别 myip.cn网站是不是在服务器保存了上千万张网页? PHP写XML时,无法向节点属性写中文值 连接服务PHP数据库 php如何读取ACCESS的ole字段内容? 很诡异的session丢失 求一个windows环境下的Zend Framework的分页程序 document.referrer在ie中无效的问题? 设置COOKIES必须在任何内容发送到浏览器之前,那么文档类型呢? mysqli_stmt_bind_param不能处理时间类型吗? PHP 模拟登陆 正方教务 php的socket
//添加数据页面
<form action="empProcess.php" method="post">
<table>
<tr><td>名字</td><td><input type="text" name="name"/></td></tr>
<tr><td>级别</td><td><input type="text" name="grade"/></td></tr>
<tr><td>邮电</td><td><input type="text" name="email"/></td></tr>
<tr><td>薪水</td><td><input type="text" name="salary"/></td></tr>
<input type="hidden" name="flag" value="addemp"/>
<tr><td><input type="submit" value="添加用户"/></td>
<td><input type="reset" value="从新填写"/></td></tr>
</table>
</form>
//处理添加数据页面并跳转
<?php
require_once 'common/EmpService.class.php';
$empService=new EmpService();
if(!empty($_REQUEST['flag'])){
$flag=$_REQUEST['flag'];
if($flag=="del"){
$id=$_GET['id'];
//echo "删除用户的id=$id";
if($empService->delEmpById($id)==1){
header("Location: ok.php");
exit();
}else{
header("Location: error.php");
exit();
}//codego.net/tags/4/1/
}else if($flag=="addemp"){
$name=$_POST['name'];
$grade=$_POST['grade'];
$email=$_POST['email'];
$salary=$_POST['salary'];
$res=$empService->addEmp($name,$grade,$email,$salary);
if($res==1){
header("Location: ok.php");
exit();
}else{
header("Location: error.php");
}
}else if($flag==updateemp){
$id=$_POST['id'];
$name=$_POST['name'];
$grade=$_POST['grade'];
$email=$_POST['email'];
$salary=$_POST['salary'];
$res=$empService->updateEmp($id,$name,$grade,$email,$salary);
if($res==1){
header("Location: ok.php");
exit();
}else{
header("Location: error.php");
}
}
}
?>
//如果成功跳转到OK页面
<?php
echo "恭喜你操作成功<br/>";
echo "<a href='empManage.php'>返回主界面</a>";
?>//这里只提供添加数据后页面跳转(数据库分层操作略)
2.跳转有很多方法,具体是看服务端还是客户端方法,参考:
header("Location:xx.php");
echo "<script>alert('操作成功');location.href='xx.php';</script>";
<form action="" method="post" name="form1" class="j" id="form1" onsubmit="submit_function(); return false;">关键在这个return false;上,告诉提交处理js函数是submit_function();之后不进行操作。
location.header("refresh:5;url=../biaodan/cx_wdksm.php");改成这样就可以了,有提交才入库。入库后跳转。<?php
if($_POST['send']=="true"){ mysql_query('INSERT INTO wdksm (time,name,mendian,bumen,zhiwu,wdktime,wdkyy,bmshtime,rsshtime)
VALUES(
\'' . $shijian . '\' ,
\'' . $conuser['xingming'] . '\' ,
\'' . $conuser['mendian'] . '\' ,
\'' . $conuser['bumen'] . '\' ,
\'' . $conuser['zhiwei'] . '\' ,
\'' . $_POST['textfield'] . '\' ,
\'' . $_POST['原因2'] . '\' ,
\'' . $_POST[''] . '\' ,
\'' . $conuser[''] . '\' )');
location.header("refresh:5;url=../biaodan/cx_wdksm.php");
}else{
?>
<div id="syzf" style="text-align:center;">
<div id="syzz" position:absolute;left:20%;width:94%;border-collapse:collapse;>
<br />
<h1 align="center">新增未打卡说明</h1>
<form action="" method="post" name="form1" class="j" id="form1">
日期:<?php echo $shijian = date("Y-m-d G:i ",mktime()); ?>
<table width="633" height="151" border="1" align="center" cellpadding="1" cellspacing="1">
<tr></tr>
<tr>
<th width="100" scope="col" style="height:30px;width:100px;">部门 </th>
<th width="100" scope="col"><?php echo $conuser['bumen'].''?>
<th width="100" scope="col">姓名</th>
<th width="100" scope="col"><?php echo $conuser['xingming'].'' ?>
<th width="100" scope="col">职务</th>
<th width="100" scope="col"><?php echo $conuser['zhiwei'].'' ?>
<tr>
<th scope="row" style="height:30px;width:150px;">未打卡时间</th>
<td colspan="5"><label for="textfield"></label>
<input name="textfield" type="text" id="textfield" value=""
style="height:30px;width:400px;"/></td>
</tr>
<tr>
<th height="46" scope="row" style="height:30px;width:100px;">未打卡原因</th>
<td colspan="5"><input name="原因2" type="text" id="原因" value=""
style="height:30px;width:400px;"/>
</tr>
<tr>
<th height="30" colspan="2" scope="row">部门责任人审批</th>
<td> </td>
<td height="30" colspan="2" class="字体" scope="row">人事行政部/总经理审批</td>
<td> </td>
</tr>
</table>
<tr><td height="30" align="center">
<input type="submit" id="hotKeyButton" name="Submit" value="提交" style="width:100px;height:35px;" />
<input type="reset" name="Reset" value="重置" style="width:100px;height:35px;" /></td></tr>
<input type="hidden" name="send" value="true">
</form>
<?php
}
?>
* 2、随页面生成
* 3、提交页面与session进行比对,成功后对session进行销毁
* 4、第二次提交则不存在这个值而报错
* @param type $uniqueid
* @return type
*/
function createToken($uniqueid) {
$uniqueid = empty($uniqueid) ? Yii::app()->user->id . Yii::app()->user->name . Yii::app()->user->mihome : $uniqueid;
$token = md5("wms_check2_repeat" . $uniqueid);
$_SESSION['form_token'] = $token;
session_write_close(); return $token;
}
function checkToken($token) {
if (!isset($_SESSION['form_token']) || empty($_SESSION['form_token']) || $_SESSION['form_token'] != $token) {
return false;
} else {
unset($_SESSION['form_token']);
return true;
}
}