<?php
include "config.php"; // Ensure this connects to your DB

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

        $deleteQuery = "DELETE FROM subject WHERE id = '$id'";

        if (mysqli_query($con, $deleteQuery)) {                                                   
            echo '<script>window.location.href = "subject.php";</script>';
        } else {
            echo "Error deleting subject: " . mysqli_error($con);
        }
    } else {
        echo "Invalid request: Subject ID is missing.";
    }
} else {
    echo "Invalid request method.";
}
?>