<?php
include 'config.php'; // database connection

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    if (isset($_POST['id'])) {
        $id = mysqli_real_escape_string($con, $_POST['id']);

        // Optional: Delete associated signature file (if needed)
        $getSignQuery = "SELECT i_sign FROM police WHERE id = '$id'";
        $result = mysqli_query($con, $getSignQuery);
        if ($row = mysqli_fetch_assoc($result)) {
            if (!empty($row['i_sign']) && file_exists($row['i_sign'])) {
                unlink($row['i_sign']); // delete the signature file
            }
        }

        $deleteQuery = "DELETE FROM police WHERE id = '$id'";
        if (mysqli_query($con, $deleteQuery)) {
                                       echo '<script>window.location.href = "police.php";</script>';
        } else {
            echo "Error deleting record: " . mysqli_error($con);
        }
    } else {
        echo "Police ID not provided.";
    }
} else {
    echo "Invalid request method.";
}
?>