我有这个页面,当打开时只读取一些会话变量并将它们分配给新变量然后取消它们,我这样做,所以它们不能转发到另一个页面。这一切都很好。
但是,我也有一个提交按钮,表单在同一页面上。出于某种原因,当我按下提交按钮时,它没有完成它应该的查询,只是重用会话检查代码。这是因为会话变量未设置,因此未通过验证。
为什么重新运行此会话验证而不运行我的提交按钮代码/
这是页面顶部的会话验证,是由于某种原因在提交按钮单击时重新运行的代码
$ahid="";
$bid="";
$np="";
$nt="";
if (isset($_SESSION['ahid'])) {
$ahid = $_SESSION['ahid'];
unset($_SESSION['ahid']);
if (isset($_SESSION['bid'])) {
$bid = $_SESSION['bid'];
unset($_SESSION['bid']);
if (isset($_SESSION['nt'])) {
$nt = $_SESSION['nt'];
unset($_SESSION['nt']);
if (isset($_SESSION['np'])) {
$np = $_SESSION['np'];
unset($_SESSION['np']);
}else{
header('Location: builders.php?hi=1');
exit();
}
}else{
header('Location: builders.php?hi=2');
exit();
}
}else{
header('Location: builders.php?hi=3');
exit();
}
}else{
header('Location: builders.php?hi=4');
exit();
}
这是应该运行的提交按钮代码,但是甚至没有触及
if(isset($_POST['build_chk_finish'])){
$construction_insert = mysql_query("INSERT INTO construction (user_id, estate_id, addon_h_id, builder_id, con_total_price, con_total_time, con_time_started, con_time_ending, con_completed)
VALUES('$user_id', '$estate_id', '$ahid', '$bid', '$np', '$nt', now(), '$future_date', '0')", $general)
or die (mysql_error());
$construction_id = mysql_insert_id();
$con_error="";
$con_error = "Congratualtions! Your Builder has been hired and has begun work.";
$_SESSION['error'] = $con_error;
header("Location: houses.php");
}
仅为了补充信息,当我按下提交按钮时,第一次会话验证builders.php?hi=4
失败。
这是提交按钮
<input name="build_chk_finish" type="submit" class="build_chk_finish" id="bc_submit"/>
答案 0 :(得分:1)
据我所知,这早午餐已经执行:
}else{
header('Location: builders.php?hi=4');
exit();
}
如果不应该,据我所知。但看看分支机构。如果未设置$ _SESSION [&#39; ahid&#39;],则会执行以上一项。那是因为其他与if (isset($_SESSION['ahid'])) {
:
if (isset($_SESSION['ahid'])) {
....// a lot of other if statements here
}else{
header('Location: builders.php?hi=4');
exit();
}