<?php
// Database connection
// Connect to MySQL

$servername = "localhost";
$username = "vinkblgn_regportal";
$password = "Victor@007";
$dbname = "vinkblgn_regportal";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}



// $conn = mysqli_connect("localhost", "vinkblgn_regportal", "Victor@007", "vinkblgn_regportal");

// Check connection
// if (!$conn) {
//     die("Connection failed: " . mysqli_connect_error());
// }

if (isset($_POST["update"])) {

    $id = $_POST['id'];
// Collect form data
$group = $_POST['group'];
$firstName = $_POST['firstname'];
$middleName = $_POST['middlename'];
$lastName = $_POST['lastname'];
$phoneNumber = $_POST['phonenumber'];
$email = $_POST['email'];
$hmo_level = $_POST['hmo_level'];
$gender = $_POST['gender'];
$dateOfBirth = $_POST['dob'];
$state = $_POST['state'];
$lga = $_POST['lga'];
$city = $_POST['city'];
$address = $_POST['address'];
$planType = $_POST['plantype'];
$groupType = $_POST['grouptype'];
$selectedProvider = $_POST['provider'];
$status = $_POST['status'];
$genotype = $_POST['genotype'];
$bloodgroup = $_POST['bloodgroup'];
$allergies = $_POST['allergies'];
$haspreexisting = $_POST['haspreexisting'];
$preexisting = $_POST['preexisting'];
$hassurgicalhist = $_POST['hassurgicalhist'];
$surgicalhist = $_POST['surgicalhist'];




// SQL query to update data in the database
$sql = "UPDATE web_app_enrollee_data 
        SET group_of_plan = '$group', 
            first_name = '$firstName', 
            middle_name = '$middleName', 
            surname = '$lastName', 
            phone_number = '$phoneNumber', 
            email_address = '$email', 
            hmo_level = '$hmo_level', 
            gender = '$gender', 
            date_of_birth = '$dateOfBirth', 
            address_state = '$state', 
            lga = '$lga', 
            address_city = '$city', 
            address_street = '$address', 
            type_of_plan = '$planType', 
            group_of_plan = '$groupType', 
            hospitals = '$selectedProvider', 
            status = '$status', 
            genotype = '$genotype', 
            blood_group = '$bloodgroup', 
            allergies = '$allergies', 
            has_pre_existing_condition = '$haspreexisting', 
            pre_existing_condition = '$preexisting', 
            has_surgical_history = '$hassurgicalhist', 
            surgical_history = '$surgicalhist'
            
        WHERE id = '$id'";

// Execute the query
if ($conn->query($sql) === TRUE) {
        header("Location:../edit.php?id=$id updated");
    exit();
} else {
    echo "Error updating record: " . $conn->error;
}
}
// Close connection
$conn->close();
?>
