<?php
include("connection.php");

ini_set('display_errors', 1);
error_reporting(E_ALL);

$id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($id <= 0) {
    die("Invalid ID");
}

// Get record
$res = mysqli_query($con, "SELECT * FROM `about_us` WHERE id = $id");
if ($res && mysqli_num_rows($res) > 0) {
    $row = mysqli_fetch_assoc($res);
    $uploadDir = "./assets/images/about/";

    // Delete image file
    if (!empty($row['image'])) {
        $file = $uploadDir . $row['image'];
        if (file_exists($file)) {
            @unlink($file);
        }
    }

    // Delete record
    mysqli_query($con, "DELETE FROM `about_us` WHERE id = $id");
}

header("Location: viewabout.php");
exit();
?>
