<?php
session_start();
if (!isset($_SESSION['username'])) { header("location:login"); exit; }
include '../functions.php';

if (isset($_GET['id'])) {
    $id = (int)$_GET['id'];

    $sel = $conn->prepare("SELECT profile_img FROM users WHERE id = ?");
    $sel->bind_param("i", $id);
    $sel->execute();
    $row = $sel->get_result()->fetch_assoc();
    $sel->close();

    if ($row && !empty($row['profile_img'])) {
        @unlink("../uploads/profile_pictures/" . basename($row['profile_img']));
    }

    $del = $conn->prepare("DELETE FROM users WHERE id = ?");
    $del->bind_param("i", $id);
    $del->execute();
    $del->close();
}
header("location:members");
exit;
