<?php
if (isset($_GET['id'])) {
    $group_id = $_GET['id'];

  include('connection.php');

    // Check if the connection was successful
    if ($conn) {
        // Escape the input to prevent SQL injection (you should use prepared statements in production)
        $group_id = mysqli_real_escape_string($conn, $group_id);

        // Prepare and execute the DELETE query
        $query = "DELETE FROM groups WHERE id = '$group_id'";
        if (mysqli_query($conn, $query)) {
            // Deletion was successful
            // header("Location: view-all-group.php"); // Redirect back to the main page or wherever you need
            // exit;
            header("Location: view-all-group.php?success = Group Delete Successfully!!!");
            exit();
        } else {
            // Handle deletion failure
            echo "Error deleting the group: " . mysqli_error($conn);
        }

        // Close the database connection
        mysqli_close($conn);
    } else {
        // Handle database connection failure
        echo "Database connection failed.";
    }
} else {
    echo "Invalid request.";
}
?>