Hi everyone

I'm creating a multi-part registration form using session, I have no problem with the first two page getting post value but whenever I validate the third page for error, it redirects me always to the first page where it should be redirected to the 2nd page once it received error validation on 3rd page..please help

here is my code for the first page

<?php
session_start();
include ('includes/navigation.php');
include ('core/init.php');
include ('helpers/helpers.php');

// SELECT GENDER
$queryGender = "SELECT * FROM gender ORDER BY id";
$resultGender = $db->query($queryGender);

// SELECT RELIGION
$queryReligion = "SELECT * FROM religion ORDER BY religion";
$resultReligion = $db->query($queryReligion);

// SELECT CIVIL STATUS
$queryCivilStatus = "SELECT * FROM civil_status ORDER BY status";
$resultCivilStatus = $db->query($queryCivilStatus);

?>
<!--  INITIALIZE SESSION FOR ERRORS -->
<?php 
if(!empty($_SESSION['error'])){
        echo $_SESSION['error'];
        unset($_SESSION['error']);
}
?>
<!DOCTYPE html>
<body>
<h2>Personal Information</h2>
<form action="familyInformation.php" method="post">
<input type="text" name="fName" placeholder="First Name*"> <input
        type="text" name="lName" placeholder="Last Name*"><br> <input
        type="text" name="address" placeholder="Address*"> <select
        name="gender">
        <option value="">Gender*</option>
            <?php while($genderResult = mysqli_fetch_assoc($resultGender)):?>
            <option value="<?= $genderResult['gender']; ?>"><?= $genderResult['gender']; ?></option>
            <?php endwhile;?>
</select><br> <input type="date" name="birthDay" placeholder="Birthday*">
    <select name="civilStatus">
        <option value="">Civil Status*</option>
                <?php while($civilStatusResult = mysqli_fetch_assoc($resultCivilStatus)): ?>
                <option value="<?= $civilStatusResult['status']; ?>"><?= $civilStatusResult['status']; ?></option>>
                <?php endwhile; ?>  
</select><br> <input type="text" name="contactNumber"
        placeholder="Contact Number*"> 
<input type="email" name="email" placeholder="Email"><br>       
        <select name="religion" id="religion" onchange="if (this.value=='Others'){this.form['otherReligion'].style.visibility='visible'}else {this.form['otherReligion'].style.visibility='hidden'};" >
        <option value="">Religion*</option>
            <?php while($religionResult = mysqli_fetch_assoc($resultReligion)): ?>
            <option value="<?= $religionResult['religion']; ?>"><?= $religionResult['religion']; ?></option>
            <?php endwhile;?>
</select><br>
<input type="text" placeholder="State Your Religion*" name="otherReligion" id="otherReligion" style="visibility:hidden;"><br> 
Language Spoken*:<input type="checkbox" name="english"  >English
                <input type="checkbox" name="tagalog" >Tagalog
                <input type="checkbox" name="kapampangan">Kapampangan
                <input type="checkbox" id="othersLanguage" name="othersLanguage"  onchange="if(document.getElementById('othersLanguage').checked){this.form['otherLanguage'].style.visibility='visible'}else {this.form['otherLanguage'].style.visibility='hidden'};">Others
                <br>
<input type="text" name="otherLanguage" id="otherLanguage" placeholder="Please list other language you know*" style="visibility: hidden;">
<input type="reset" value="reset" name="reset1">
<input type="submit" value="next" name="register1">

</form>

</body>
</html>

here is on the 2nd page still no problem for validation.. it redirects me to first page

<?php
session_start();
include ('includes/navigation.php');
include ('core/init.php');
//validation of input
if( empty($_POST['fName']) || 
    !isset($_POST['fName'])||
    empty($_POST['lName']) ||
    !isset($_POST['lName']) ||
    empty($_POST['address']) ||
    !isset($_POST['address']) ||
    empty($_POST['gender']) ||
    !isset($_POST['gender']) ||
    empty($_POST['birthDay']) ||
    !isset($_POST['birthDay']) ||
    empty($_POST['civilStatus']) ||
    !isset($_POST['civilStatus']) ||
    empty($_POST['contactNumber']) ||
    !isset($_POST['contactNumber']) ||
    empty($_POST['religion']) ||
    !isset($_POST['religion'])){ 
    $_SESSION['error'] = 'Please fill all required field';
    header ('location: registration.php');

}
else if(!isset($_POST['english']) && !isset($_POST['tagalog']) && !isset($_POST['kapampangan']) && !isset($_POST['othersLanguage'])){
        $_SESSION['error'] = 'You did not fill up language spoken';
        header('location: registration.php');
}
else{ 
            if(isset($_POST['english'])){
                $_POST['english'] = '1';
            }
            if(isset($_POST['tagalog'])){
                $_POST['tagalog'] = '1';
            }
            if(isset($_POST['kapampangan'])){
                $_POST['kapampangan'] = '1';
            }
            if($_POST['religion'] == 'Others' ){

              if(empty($_POST['otherReligion']) || !isset($_POST['otherReligion'])){
                  $_SESSION['error'] = "You did not state your religion";
                  header('location:registration.php');
              }else{
                  $_POST['religion'] = $_POST['otherReligion'];
              }

          }
          if(isset($_POST['othersLanguage'])){
            if(empty($_POST['otherLanguage']) || !isset($_POST['otherLanguage'])){
                $_SESSION['error'] = 'You did not list other language you know';
                header ('location:registration.php');
            }

        }

            foreach ($_POST as $key => $value) {
                $_SESSION['post'][$key] = $value;
                    }
}
?>
<!--  INITIALIZE SESSION FOR ERRORS -->
<?php 
if(!empty($_SESSION['familyInformationError'])){
        echo $_SESSION['familyInformationError'];
        unset($_SESSION['familyInformationError']);
}
?>
<h2>Family Information</h2><hr>
<form action="governmentInsurance.php" method="POST">
<input type="text" name="fathersName" placeholder="Fathers Name">
<input type="text" name="mothersName" placeholder="Mothers Name">
<input type="text" name="spouseName" placeholder = "Name of Spouse"   style="visibility:<?= (($_POST['civilStatus'] == 'single')?'hidden':'visible'); ?>;">
<input type="submit" value="submit">
</form>

but here is the problem, the third page, once I perform validation code, it always redirect me to first page where I should be redirected to second page

<?php
session_start();
include ('includes/navigation.php');
include ('core/init.php');

if(empty($_POST['fathersName']) ||
    !isset($_POST['fathersName']) ||
    empty($_POST['mothersName']) ||
    !isset($_POST['mothersName'])){
    $_SESSION['familyInformationError'] = 'Hello World';
    header('location:familyInformation.php');

}else{
    foreach ($_POST as $key => $value) {
        $_SESSION['post'][$key] = $value;
}

} 
?>

<h2>Government Insurance ID</h2>
<form action="process2.php" method="POST">
<input type="text" name="sssNumber" placeholder="SSS Number">
<input type="text" name="pagIbigNumber" placeholder="PAG-IBIG Number">
<input type="text" name="philHealthNumber" placeholder = "PHILHEALTH NUMBER">
<input type="text" name="tinNumber" placeholder="TIN Number">
<input type="submit" value="submit">
</form>

please help

Member Avatar for diafol

Sounds like a double redirect. Page 3 -> Page 2 -> page 1.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.