<?php
// 🔐 Protect page
include("auth.php");
include("config/db.php");

if (!isset($_GET['id'])) {
    header("Location: slider.php");
    exit;
}

$id = (int)$_GET['id'];

// Get image name
$res = mysqli_query($conn, "SELECT image FROM slider WHERE id = $id");
$row = mysqli_fetch_assoc($res);

if ($row) {

    $imagePath = "uploads/slider/" . $row['image'];

    // Delete image file if exists
    if (!empty($row['image']) && file_exists($imagePath)) {
        unlink($imagePath);
    }

    // Delete record from DB
    mysqli_query($conn, "DELETE FROM slider WHERE id = $id");
}

// Redirect back
header("Location: slider.php");
exit;
