<?php

include_once './data/dbconn.php';


// Handle form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    
   // Get the last enrollment serial number from the database
    $query = "SELECT (`enrollment_serial_no`) FROM (`web_app_enrollee_data`) ORDER BY id DESC LIMIT 1";

    $result = $conn->query($query);

    if ($result && $result->num_rows > 0) {
        $lastEnrollmentSerial = $result->fetch_assoc()['enrollment_serial_no'];
        // Increment the last enrollment serial number by 1
        $enrollmentSerialno = $lastEnrollmentSerial + 1;
    } else {
        // If there are no records in the database, start with a default value
        $enrollmentSerialno = 1000;
    }
    // File upload handling
    $targetDir = "uploads/"; // Directory where files will be uploaded
    $imageFileType = strtolower(pathinfo($_FILES["q99_passport"]["name"], PATHINFO_EXTENSION));
    $hmoId = $_POST['q110_hmoId'] . $enrollmentSerialno; // Assuming q110_hmoId contains the HMO ID

    // Set the target file name to HMO ID + enrollment serial number + extension
    $targetFile = $targetDir .$enrollmentSerialno . '.' . $imageFileType;

    $uploadOk = 1;

    // Check file size
    if ($_FILES["q99_passport"]["size"] > 10485760) {
        echo "Sorry, your file is too large.";
        $uploadOk = 0;
    }

    // Allow only certain file formats
    if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
        && $imageFileType != "gif") {
        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        $uploadOk = 0;
    }

    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
    // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["q99_passport"]["tmp_name"], $targetFile)) {
            // echo "The file " . basename($_FILES["q99_passport"]["name"]) . " has been uploaded.";
            
            
    $companyName = $_POST['q98_companyName'];
    $surname = $_POST['q4_surname'];
    $firstName = $_POST['q26_firstName'];
    $middleName = $_POST['q27_middleName'];
    $gender = $_POST['q22_gender'];
    $phoneNumber = $_POST['q23_phoneNumber23'];
    $emailAddress = $_POST['q24_emailAddress'];
    $dateOfBirth = $_POST['q9_dateOf']['day'] . '/' . $_POST['q9_dateOf']['month'] . '/' . $_POST['q9_dateOf']['year'];
    $groupOfPlan = $_POST['q106_groupOf'];
    $typeOfPlan = $_POST['q30_typeOf30'];
    $streetAddress = $_POST['q20_address']['addr_line1'];
    $streetAddress2 = $_POST['q20_address']['addr_line2'];
    $city = $_POST['q20_address']['city'];
    $state = $_POST['q20_address']['state'];
    $lga = $_POST['q20_address']['postal'];
    $employeeId = $_POST['q29_employeeId'];
    $hospitals = $_POST['q31_hospitalsx'];
    $genotype = $_POST['q_genotype'];
    $bloodGroup = $_POST['q_bloodgroup'];
    $allergies = $_POST['q_allergies'];
    $haspreexistingcondition = $_POST['q_Preextcon'];
    $preexistingcondition = $_POST['q_Preextconans'];
    $hassurgicalhistory = $_POST['q_surgicalque'];
    $surgicalHistory = $_POST['q_surgical'];
    $fileLink = 'https://healthassur.com/enrollment/'.$targetFile;

    // Insert new company data into the database, including file link
    $m_errs = "INSERT INTO `web_app_enrollee_data` ( `id` , `enrollment_serial_no`, `company_name` , `surname`, `first_name`, `middle_name`, `gender` , `phone_number` ,
    `email_address`, `date_of_birth`, `group_of_plan`, `type_of_plan` , `hmo_id`, `address_street` , `address_city`, `address_state`, `lga`, `employee_id` , `hospitals` ,
    `genotype`, `blood_group`, `allergies`, `has_pre_existing_condition`, `pre_existing_condition`, `has_surgical_history`, `surgical_history`, `Passport_link` ) 
    VALUES ( NULL , '$enrollmentSerialno', '$companyName', '$surname', '$firstName', '$middleName', '$gender', '$phoneNumber', '$emailAddress', '$dateOfBirth', '$groupOfPlan',
    '$typeOfPlan', '$hmoId', '$streetAddress', '$city', '$state', '$lga', '$employeeId', '$hospitals', '$genotype', '$bloodGroup', '$allergies', '$haspreexistingcondition',
    '$preexistingcondition', '$hassurgicalhistory', '$surgicalHistory', '$fileLink')";

    $conn->query($m_errs);
   
    
    //Spouse
    if ($_POST['spouseq4_surname']){
        
        $spousesurname = $_POST['spouseq4_surname'];
        
        if ($spousesurname != ''){
        // Get the last enrollment serial number from the database
        $query = "SELECT (`enrollment_serial_no`) FROM (`web_app_enrollee_data`) ORDER BY id DESC LIMIT 1";
    
        $result = $conn->query($query);
    
        if ($result && $result->num_rows > 0) {
            $lastEnrollmentSerial = $result->fetch_assoc()['enrollment_serial_no'];
            // Increment the last enrollment serial number by 1
            $spouseenrollmentSerialno = $lastEnrollmentSerial + 1;
        } else {
            // If there are no records in the database, start with a default value
            $spouseenrollmentSerialno = 1000;
        }
        // File upload handling
        $targetDir = "uploads/"; // Directory where files will be uploaded
        $imageFileType = strtolower(pathinfo($_FILES["spouseq99_passport"]["name"], PATHINFO_EXTENSION));
        
        $spousehmoId = $_POST['q110_hmoId'] . $enrollmentSerialno . '/B'; // Assuming q110_hmoId contains the HMO ID
    
        // Set the target file name to HMO ID + enrollment serial number + extension
        $targetFile = $targetDir .$spouseenrollmentSerialno . '.' . $imageFileType;
        
        $spousefileLink = 'https://healthassur.com/enrollment/'.$targetFile;
    
        $uploadOk = 1;
    
        // Check file size
        if ($_FILES["spouseq99_passport"]["size"] > 10485760) {
            echo "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        
        // Allow only certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif") {
            echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
    
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["spouseq99_passport"]["tmp_name"], $targetFile)) {
                
                $spousefirstName = $_POST['spouseq26_firstName'];
                $spousemiddleName = $_POST['spouseq27_middleName'];
                $spousegender = $_POST['spouseq22_gender'];
                $spousephoneNumber = $_POST['spouseq23_phoneNumber23'];
                $spouseemailAddress = $_POST['spouseq24_emailAddress'];
                $spousedateOfBirth = $_POST['spouseq9_dateOf']['day'] . '/' . $_POST['spouseq9_dateOf']['month'] . '/' . $_POST['spouseq9_dateOf']['year'];
                $spousehospitals = $_POST['spouseq31_hospitalsx'];
                $spousegenotype = $_POST['spouseq_genotype'];
                $spousebloodGroup = $_POST['spousespouseq_bloodgroup'];
                $spouseallergies = $_POST['spouseq_allergies'];
                $spousehaspreexistingcondition = $_POST['spouseq_Preextcon'];
                $spousepreexistingcondition = $_POST['spouseq_Preextconans'];
                $spousehassurgicalhistory = $_POST['spouseq_surgicalque'];
                $spousesurgicalHistory = $_POST['spouseq_surgical'];
                $hmolevel = 'Spouse';
                
        $spousedata = "INSERT INTO `web_app_enrollee_data` ( `id` , `enrollment_serial_no`, `company_name` , `surname`, `first_name`, `middle_name`, `gender` ,
        `email_address`, `date_of_birth`, `group_of_plan`, `type_of_plan` ,  `hmo_id`, `address_street` , `address_city`, `address_state`, `lga`, `hospitals` ,
        `genotype`, `blood_group`, `allergies`, `has_pre_existing_condition`, `pre_existing_condition`, `has_surgical_history`, `surgical_history`, `Passport_link`, `hmo_level` ) 
        VALUES ( NULL , '$spouseenrollmentSerialno', '$companyName', '$spousesurname', '$spousefirstName',             '$spousemiddleName', '$spousegender', '$spouseemailAddress', 
            '$spousedateOfBirth', '$groupOfPlan',
    '$typeOfPlan', '$spousehmoId', '$streetAddress', '$city', '$state', '$lga', '$spousehospitals', '$spousegenotype', '$spousebloodGroup', '$spouseallergies', '$spousehaspreexistingcondition','$spousepreexistingcondition', '$spousehassurgicalhistory', '$spousesurgicalHistory', '$spousefileLink', '$hmolevel')";
        
        
            $conn->query($spousedata);
            
            }
        }
            
        }
        
    }
    
    //1st Dependant
    
    if ($_POST['depen1q4_surname']){
        
        $depen1surname = $_POST['depen1q4_surname'];
        
        if ($depen1surname != ''){
        // Get the last enrollment serial number from the database
        $query = "SELECT (`enrollment_serial_no`) FROM (`web_app_enrollee_data`) ORDER BY id DESC LIMIT 1";
    
        $result = $conn->query($query);
    
        if ($result && $result->num_rows > 0) {
            $lastEnrollmentSerial = $result->fetch_assoc()['enrollment_serial_no'];
            // Increment the last enrollment serial number by 1
            $depen1enrollmentSerialno = $lastEnrollmentSerial + 1;
        } else {
            // If there are no records in the database, start with a default value
            $depen1enrollmentSerialno = 1000;
        }
        // File upload handling
        $targetDir = "uploads/"; // Directory where files will be uploaded
        $imageFileType = strtolower(pathinfo($_FILES["depen1q99_passport"]["name"], PATHINFO_EXTENSION));
        
        $depen1hmoId = $_POST['q110_hmoId'] . $enrollmentSerialno . '/C'; // Assuming q110_hmoId contains the HMO ID
    
        // Set the target file name to HMO ID + enrollment serial number + extension
        $targetFile = $targetDir .$depen1enrollmentSerialno . '.' . $imageFileType;
        
        $depen1fileLink = 'https://healthassur.com/enrollment/'.$targetFile;
    
        $uploadOk = 1;
    
        // Check file size
        if ($_FILES["depen1q99_passport"]["size"] > 10485760) {
            echo "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        
        // Allow only certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif") {
            echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
    
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["depen1q99_passport"]["tmp_name"], $targetFile)) {
                
                $depen1firstName = $_POST['depen1q26_firstName'];
                $depen1middleName = $_POST['depen1q27_middleName'];
                $depen1gender = $_POST['depen1q22_gender'];
                $depen1phoneNumber = $_POST['depen1q23_phoneNumber23'];
                $depen1emailAddress = $_POST['depen1q24_emailAddress'];
                $depen1dateOfBirth = $_POST['depen1q9_dateOf']['day'] . '/' . $_POST['depen1q9_dateOf']['month'] . '/' . $_POST['depen1q9_dateOf']['year'];
                $depen1hospitals = $_POST['depen1q31_hospitalsx'];
                $depen1genotype = $_POST['depen1q_genotype'];
                $depen1bloodGroup = $_POST['depen1depen1q_bloodgroup'];
                $depen1allergies = $_POST['depen1q_allergies'];
                $depen1haspreexistingcondition = $_POST['depen1q_Preextcon'];
                $depen1preexistingcondition = $_POST['depen1q_Preextconans'];
                $depen1hassurgicalhistory = $_POST['depen1q_surgicalque'];
                $depen1surgicalHistory = $_POST['depen1q_surgical'];
                $hmolevel = '1st Child';
                
        $depen1data = "INSERT INTO `web_app_enrollee_data` ( `id` , `enrollment_serial_no`, `company_name` , `surname`, `first_name`, `middle_name`, `gender` ,
        `email_address`, `date_of_birth`, `group_of_plan`, `type_of_plan` ,  `hmo_id`, `address_street` , `address_city`, `address_state`, `lga`, `hospitals` ,
        `genotype`, `blood_group`, `allergies`, `has_pre_existing_condition`, `pre_existing_condition`, `has_surgical_history`, `surgical_history`, `Passport_link`, `hmo_level` ) 
        VALUES ( NULL , '$depen1enrollmentSerialno', '$companyName', '$depen1surname', '$depen1firstName',             '$depen1middleName', '$depen1gender', '$depen1emailAddress', 
            '$depen1dateOfBirth', '$groupOfPlan',
    '$typeOfPlan', '$depen1hmoId', '$streetAddress', '$city', '$state', '$lga', '$depen1hospitals', '$depen1genotype', '$depen1bloodGroup', '$depen1allergies', '$depen1haspreexistingcondition','$depen1preexistingcondition', '$depen1hassurgicalhistory', '$depen1surgicalHistory', '$depen1fileLink', '$hmolevel')";
        
        
            $conn->query($depen1data);
            
            }
        }
            
        }
        
    }
    
    //2nd Dependant
    
    if ($_POST['depen2q4_surname']){
        
        $depen2surname = $_POST['depen2q4_surname'];
        
        if ($depen2surname != ''){
        // Get the last enrollment serial number from the database
        $query = "SELECT (`enrollment_serial_no`) FROM (`web_app_enrollee_data`) ORDER BY id DESC LIMIT 1";
    
        $result = $conn->query($query);
    
        if ($result && $result->num_rows > 0) {
            $lastEnrollmentSerial = $result->fetch_assoc()['enrollment_serial_no'];
            // Increment the last enrollment serial number by 1
            $depen2enrollmentSerialno = $lastEnrollmentSerial + 1;
        } else {
            // If there are no records in the database, start with a default value
            $depen2enrollmentSerialno = 1000;
        }
        // File upload handling
        $targetDir = "uploads/"; // Directory where files will be uploaded
        $imageFileType = strtolower(pathinfo($_FILES["depen2q99_passport"]["name"], PATHINFO_EXTENSION));
        
        $depen2hmoId = $_POST['q110_hmoId'] . $enrollmentSerialno . '/D'; // Assuming q110_hmoId contains the HMO ID
    
        // Set the target file name to HMO ID + enrollment serial number + extension
        $targetFile = $targetDir .$depen2enrollmentSerialno . '.' . $imageFileType;
        
        $depen2fileLink = 'https://healthassur.com/enrollment/'.$targetFile;
    
        $uploadOk = 1;
    
        // Check file size
        if ($_FILES["depen2q99_passport"]["size"] > 10485760) {
            echo "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        
        // Allow only certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif") {
            echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
    
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["depen2q99_passport"]["tmp_name"], $targetFile)) {
                
                $depen2firstName = $_POST['depen2q26_firstName'];
                $depen2middleName = $_POST['depen2q27_middleName'];
                $depen2gender = $_POST['depen2q22_gender'];
                $depen2phoneNumber = $_POST['depen2q23_phoneNumber23'];
                $depen2emailAddress = $_POST['depen2q24_emailAddress'];
                $depen2dateOfBirth = $_POST['depen2q9_dateOf']['day'] . '/' . $_POST['depen2q9_dateOf']['month'] . '/' . $_POST['depen2q9_dateOf']['year'];
                $depen2hospitals = $_POST['depen2q31_hospitalsx'];
                $depen2genotype = $_POST['depen2q_genotype'];
                $depen2bloodGroup = $_POST['depen2depen2q_bloodgroup'];
                $depen2allergies = $_POST['depen2q_allergies'];
                $depen2haspreexistingcondition = $_POST['depen2q_Preextcon'];
                $depen2preexistingcondition = $_POST['depen2q_Preextconans'];
                $depen2hassurgicalhistory = $_POST['depen2q_surgicalque'];
                $depen2surgicalHistory = $_POST['depen2q_surgical'];
                $hmolevel = '2nd Child';
                
        $depen2data = "INSERT INTO `web_app_enrollee_data` ( `id` , `enrollment_serial_no`, `company_name` , `surname`, `first_name`, `middle_name`, `gender` ,
        `email_address`, `date_of_birth`, `group_of_plan`, `type_of_plan` ,  `hmo_id`, `address_street` , `address_city`, `address_state`, `lga`, `hospitals` ,
        `genotype`, `blood_group`, `allergies`, `has_pre_existing_condition`, `pre_existing_condition`, `has_surgical_history`, `surgical_history`, `Passport_link`, `hmo_level` ) 
        VALUES ( NULL , '$depen2enrollmentSerialno', '$companyName', '$depen2surname', '$depen2firstName',             '$depen2middleName', '$depen2gender', '$depen2emailAddress', 
            '$depen2dateOfBirth', '$groupOfPlan',
    '$typeOfPlan', '$depen2hmoId', '$streetAddress', '$city', '$state', '$lga', '$depen2hospitals', '$depen2genotype', '$depen2bloodGroup', '$depen2allergies', '$depen2haspreexistingcondition','$depen2preexistingcondition', '$depen2hassurgicalhistory', '$depen2surgicalHistory', '$depen2fileLink', '$hmolevel')";
        
        
            $conn->query($depen2data);
            
            }
        }
            
        }
        
    }
    
    //3rd Dependant
    
    if ($_POST['depen3q4_surname']){
        
        $depen3surname = $_POST['depen3q4_surname'];
        
        if ($depen3surname != ''){
        // Get the last enrollment serial number from the database
        $query = "SELECT (`enrollment_serial_no`) FROM (`web_app_enrollee_data`) ORDER BY id DESC LIMIT 1";
    
        $result = $conn->query($query);
    
        if ($result && $result->num_rows > 0) {
            $lastEnrollmentSerial = $result->fetch_assoc()['enrollment_serial_no'];
            // Increment the last enrollment serial number by 1
            $depen3enrollmentSerialno = $lastEnrollmentSerial + 1;
        } else {
            // If there are no records in the database, start with a default value
            $depen3enrollmentSerialno = 1000;
        }
        // File upload handling
        $targetDir = "uploads/"; // Directory where files will be uploaded
        $imageFileType = strtolower(pathinfo($_FILES["depen3q99_passport"]["name"], PATHINFO_EXTENSION));
        
        $depen3hmoId = $_POST['q110_hmoId'] . $enrollmentSerialno . '/E'; // Assuming q110_hmoId contains the HMO ID
    
        // Set the target file name to HMO ID + enrollment serial number + extension
        $targetFile = $targetDir .$depen3enrollmentSerialno . '.' . $imageFileType;
        
        $depen3fileLink = 'https://healthassur.com/enrollment/'.$targetFile;
    
        $uploadOk = 1;
    
        // Check file size
        if ($_FILES["depen3q99_passport"]["size"] > 10485760) {
            echo "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        
        // Allow only certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif") {
            echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
    
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["depen3q99_passport"]["tmp_name"], $targetFile)) {
                
                $depen3firstName = $_POST['depen3q26_firstName'];
                $depen3middleName = $_POST['depen3q27_middleName'];
                $depen3gender = $_POST['depen3q22_gender'];
                $depen3phoneNumber = $_POST['depen3q23_phoneNumber23'];
                $depen3emailAddress = $_POST['depen3q24_emailAddress'];
                $depen3dateOfBirth = $_POST['depen3q9_dateOf']['day'] . '/' . $_POST['depen3q9_dateOf']['month'] . '/' . $_POST['depen3q9_dateOf']['year'];
                $depen3hospitals = $_POST['depen3q31_hospitalsx'];
                $depen3genotype = $_POST['depen3q_genotype'];
                $depen3bloodGroup = $_POST['depen3depen3q_bloodgroup'];
                $depen3allergies = $_POST['depen3q_allergies'];
                $depen3haspreexistingcondition = $_POST['depen3q_Preextcon'];
                $depen3preexistingcondition = $_POST['depen3q_Preextconans'];
                $depen3hassurgicalhistory = $_POST['depen3q_surgicalque'];
                $depen3surgicalHistory = $_POST['depen3q_surgical'];
                $hmolevel = '3rd Child';
                
        $depen3data = "INSERT INTO `web_app_enrollee_data` ( `id` , `enrollment_serial_no`, `company_name` , `surname`, `first_name`, `middle_name`, `gender` ,
        `email_address`, `date_of_birth`, `group_of_plan`, `type_of_plan` ,  `hmo_id`, `address_street` , `address_city`, `address_state`, `lga`, `hospitals` ,
        `genotype`, `blood_group`, `allergies`, `has_pre_existing_condition`, `pre_existing_condition`, `has_surgical_history`, `surgical_history`, `Passport_link`, `hmo_level` ) 
        VALUES ( NULL , '$depen3enrollmentSerialno', '$companyName', '$depen3surname', '$depen3firstName',             '$depen3middleName', '$depen3gender', '$depen3emailAddress', 
            '$depen3dateOfBirth', '$groupOfPlan',
    '$typeOfPlan', '$depen3hmoId', '$streetAddress', '$city', '$state', '$lga', '$depen3hospitals', '$depen3genotype', '$depen3bloodGroup', '$depen3allergies', '$depen3haspreexistingcondition','$depen3preexistingcondition', '$depen3hassurgicalhistory', '$depen3surgicalHistory', '$depen3fileLink', '$hmolevel')";
        
        
            $conn->query($depen3data);
            
            }
        }
            
        }
        
    }
    
    //4th Dependant
    
    if ($_POST['depen4q4_surname']){
        
        $depen4surname = $_POST['depen4q4_surname'];
        
        if ($depen4surname != ''){
        // Get the last enrollment serial number from the database
        $query = "SELECT (`enrollment_serial_no`) FROM (`web_app_enrollee_data`) ORDER BY id DESC LIMIT 1";
    
        $result = $conn->query($query);
    
        if ($result && $result->num_rows > 0) {
            $lastEnrollmentSerial = $result->fetch_assoc()['enrollment_serial_no'];
            // Increment the last enrollment serial number by 1
            $depen4enrollmentSerialno = $lastEnrollmentSerial + 1;
        } else {
            // If there are no records in the database, start with a default value
            $depen4enrollmentSerialno = 1000;
        }
        // File upload handling
        $targetDir = "uploads/"; // Directory where files will be uploaded
        $imageFileType = strtolower(pathinfo($_FILES["depen4q99_passport"]["name"], PATHINFO_EXTENSION));
        
        $depen4hmoId = $_POST['q110_hmoId'] . $enrollmentSerialno . '/F'; // Assuming q110_hmoId contains the HMO ID
    
        // Set the target file name to HMO ID + enrollment serial number + extension
        $targetFile = $targetDir .$depen4enrollmentSerialno . '.' . $imageFileType;
        
        $depen4fileLink = 'https://healthassur.com/enrollment/'.$targetFile;
    
        $uploadOk = 1;
    
        // Check file size
        if ($_FILES["depen4q99_passport"]["size"] > 10485760) {
            echo "Sorry, your file is too large.";
            $uploadOk = 0;
        }
        
        // Allow only certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif") {
            echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
    
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["depen4q99_passport"]["tmp_name"], $targetFile)) {
                
                $depen4firstName = $_POST['depen4q26_firstName'];
                $depen4middleName = $_POST['depen4q27_middleName'];
                $depen4gender = $_POST['depen4q22_gender'];
                $depen4phoneNumber = $_POST['depen4q23_phoneNumber23'];
                $depen4emailAddress = $_POST['depen4q24_emailAddress'];
                $depen4dateOfBirth = $_POST['depen4q9_dateOf']['day'] . '/' . $_POST['depen4q9_dateOf']['month'] . '/' . $_POST['depen4q9_dateOf']['year'];
                $depen4hospitals = $_POST['depen4q31_hospitalsx'];
                $depen4genotype = $_POST['depen4q_genotype'];
                $depen4bloodGroup = $_POST['depen4depen4q_bloodgroup'];
                $depen4allergies = $_POST['depen4q_allergies'];
                $depen4haspreexistingcondition = $_POST['depen4q_Preextcon'];
                $depen4preexistingcondition = $_POST['depen4q_Preextconans'];
                $depen4hassurgicalhistory = $_POST['depen4q_surgicalque'];
                $depen4surgicalHistory = $_POST['depen4q_surgical'];
                $hmolevel = '4th Child';
                
        $depen4data = "INSERT INTO `web_app_enrollee_data` ( `id` , `enrollment_serial_no`, `company_name` , `surname`, `first_name`, `middle_name`, `gender` ,
        `email_address`, `date_of_birth`, `group_of_plan`, `type_of_plan` ,  `hmo_id`, `address_street` , `address_city`, `address_state`, `lga`, `hospitals` ,
        `genotype`, `blood_group`, `allergies`, `has_pre_existing_condition`, `pre_existing_condition`, `has_surgical_history`, `surgical_history`, `Passport_link`, `hmo_level` ) 
        VALUES ( NULL , '$depen4enrollmentSerialno', '$companyName', '$depen4surname', '$depen4firstName',             '$depen4middleName', '$depen4gender', '$depen4emailAddress', 
            '$depen4dateOfBirth', '$groupOfPlan',
    '$typeOfPlan', '$depen4hmoId', '$streetAddress', '$city', '$state', '$lga', '$depen4hospitals', '$depen4genotype', '$depen4bloodGroup', '$depen4allergies', '$depen4haspreexistingcondition','$depen4preexistingcondition', '$depen4hassurgicalhistory', '$depen4surgicalHistory', '$depen4fileLink', '$hmolevel')";
        
        
            $conn->query($depen4data);
            
            }
        }
            
        }
        
    }

        header("Location: ./success.html");
        exit(); 
        // Make sure no other output is sent
        
        } else {
            echo "Sorry, there was an error uploading your file.";
        }
    }
    

}