<?php
include "dbconnect.php";

// Ensure that the 'id' parameter is passed and valid
$id = isset($_POST['id']) ? (int)$_POST['id'] : 0;
if ($id <= 0) {
    die('Invalid ID');
}

// Get the updated appointment data
$appointment_date = isset($_POST['appointment_date']) ? $_POST['appointment_date'] : '';
$status = isset($_POST['status']) ? $_POST['status'] : '';

// Validate input
if (empty($appointment_date) || empty($status)) {
    die('All fields are required');
}

// Update the appointment details in the database
$sql = "UPDATE appointments SET appointment_date = ?, status = ? WHERE applicant_id = ?";
$stmt = $con->prepare($sql);
$stmt->bind_param('ssi', $appointment_date, $status, $id);

if ($stmt->execute()) {
    echo "Appointment updated successfully.";
    // Redirect to another page (e.g., appointment list page)
    header('Location: appointment_list.php');
    exit();
} else {
    echo "Error updating appointment: " . $con->error;
}

$stmt->close();
$con->close();
?>
