<?php
include "config/db.php";

$id = $_GET['id'];

$blog = mysqli_fetch_assoc(
    mysqli_query($conn, "SELECT image FROM blogs WHERE id='$id'")
);

// delete image file
if (file_exists("uploads/blogs/" . $blog['image'])) {
    unlink("uploads/blogs/" . $blog['image']);
}

// delete record
mysqli_query($conn, "DELETE FROM blogs WHERE id='$id'");

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