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

include_once '../dbconn.php';

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'];
$current_date = date("Y-m-d H:i:s");




// 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',
            newchanges = 'yes',
            changedate = '$current_date'
            
            
        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();
?>
