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

include_once '../dbconn.php';

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

    $id = $_POST['id'];
// Collect form data
$submission_id = $_POST['submission_id'];
$title = $_POST['title'];
$first_name = $_POST['first_name'];
$middle_name = $_POST['middle_name'];
$last_name = $_POST['last_name'];
$fullname = $_POST['last_name'] . $_POST['middle_name'] . $_POST['first_name'];
$id_number = $_POST['id_number'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$deanery_name = $_POST['deanery_name'];
$parish_name = $_POST['parish_name'];
$cmo_induction_status = $_POST['cmo_induction_status'];
$blood_group = $_POST['blood_group'];
$do_you_require_a_mattress_to_sleep_over = $_POST['do_you_require_a_mattress_to_sleep_over'];
$do_you_require_a_hotel_accommodation = $_POST['do_you_require_a_hotel_accommodation'];
$if_yes_click_a_range = $_POST['if_yes_click_a_range'];
$how_long_have_you_been_canonically_married = $_POST['how_long_have_you_been_canonically_married'];
$approval_status = $_POST['approval_status'];




// SQL query to update data in the database
$sql = "UPDATE submissions 
        SET title = '$title', 
            first_name = '$first_name', 
            middle_name = '$middle_name', 
            last_name = '$last_name', 
            fullname = '$fullname', 
            id_number = '$id_number', 
            phone = '$phone', 
            email = '$email', 
            deanery_name = '$deanery_name', 
            parish_name = '$parish_name', 
            cmo_induction_status = '$cmo_induction_status', 
            blood_group = '$blood_group', 
            do_you_require_a_mattress_to_sleep_over = '$do_you_require_a_mattress_to_sleep_over', 
            do_you_require_a_hotel_accommodation = '$do_you_require_a_hotel_accommodation', 
            if_yes_click_a_range = '$if_yes_click_a_range', 
            how_long_have_you_been_canonically_married = '$how_long_have_you_been_canonically_married',
            approval_status = '$approval_status'
            
        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();
?>
