<?php

session_start();


if(!isset($_SESSION['user_id'])){

    header("Location:login.php");
    exit;

}


require_once "config.php";



$id=$_GET['id'] ?? 0;



if(!$id){

    header("Location:users.php");
    exit;

}




// PREVENT SELF DELETE

if($id==$_SESSION['user_id']){


$_SESSION['error']="You cannot delete your own account";


header("Location:users.php");

exit;


}




$stmt=$pdo->prepare("

DELETE FROM users

WHERE id=?

");


$stmt->execute([$id]);




$_SESSION['success']="User deleted successfully";


header("Location:users.php");

exit;


?>