<?php

include("../../config/config.php");

$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$gender = $_POST['gender'];
$dateofbirth = $_POST['dateofbirth'];
$age = $_POST['age'];
$maritalstatus = $_POST['maritalstatus'];
$phonenumber = $_POST['phonenumber'];
$emailaddress = $_POST['emailaddress'];
$homeaddress = $_POST['homeaddress'];

$select_for_born_again = "SELECT * FROM `bornagain` WHERE `FirstName` = '$firstname' AND `MiddleName` = '$middlename' AND `LastName` = '$lastname' 
AND `Gender` = '$gender' AND `DateOfBirth` = '$dateofbirth' AND `Age` = '$age' AND `MaritalStatus` = '$maritalstatus' AND `PhoneNumber` = '$phonenumber' 
AND `EmailAddress` = '$emailaddress' AND `HomeAddress` = '$homeaddress' ";
$query_for_born_again = mysqli_query($link, $select_for_born_again);
$fetch_for_born_again = mysqli_fetch_assoc($query_for_born_again);
$rows_for_born_again = mysqli_num_rows($query_for_born_again);

if($rows_for_born_again == 0){
    $insert_bornagain = "INSERT INTO `bornagain`(`FirstName`, `MiddleName`, `LastName`, `PhoneNumber`, `EmailAddress`, `Gender`, `MaritalStatus`, `DateOfBirth`, `Age`, `HomeAddress`) 
    VALUES ('$firstname','$middlename','$lastname','$phonenumber','$emailaddress','$gender','$maritalstatus','$dateofbirth','$age','$homeaddress')";
    $insert_bornagain_query = mysqli_query($link, $insert_bornagain);
    
    if($insert_bornagain_query == true){
        echo 1;
    }else{
        echo 2;
    }    
}else{
    echo 3;
}


?>