I have this page which when opened just reads in some session variables and assigns them to new variables and then unsets them, I do this so they can’t be carried forward to another page. This all works good.
But, I also have a submit button with a form on the same page. For some reason, when I press the submit button, it is not completing the queries it should and just reuses the session checking code. Which because the session variables are unset, then fails the validation for them.
Why is it re-running this session validation and not running my submit button code/
This is the session validation at the very top of the page, and is the code which for some reason is re-run on submit button click
$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();
}
This is the submit button code that should be run, but instead is not even touched
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");
}
Just for added info, when I press the submit button it is failing on the first session validation builders.php?hi=4.
Here is the submit button
<input name="build_chk_finish" type="submit" class="build_chk_finish" id="bc_submit"/>
as I understand, this brunch is executed:
When it should not, as I understand. But take a look at if branches. One above will be executed any time when $_SESSION[‘ahid’] is not set. That is because that else is related to
if (isset($_SESSION['ahid'])) {: