<?php
session_start();
include "config.php"; // Make sure this connects to your DB

if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["id"]) && isset($_POST["isDeleted"])) {
    $id = intval($_POST["id"]);
    $isDeleted = intval($_POST["isDeleted"]);  // Expect 0 or 1

    $query = "UPDATE user SET isDeleted = $isDeleted, time_stamp = NOW() WHERE id = $id";

    if (mysqli_query($con, $query)) {
                    echo '<script>window.location.href = "users.php";</script>';

    } else {
        echo "Error updating user: " . mysqli_error($con);
    }

    mysqli_close($con);
} else {
    header("Location: users.php");
    exit();
}