<?php
include "db.php";

if (isset($_POST['id'])) {
    $id = intval($_POST['id']);

    $result = mysqli_query($conn, "SELECT image FROM blogs WHERE id = $id");
    $row = mysqli_fetch_assoc($result);
    $image = $row['image'];

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

    if ($delete) {
      
        if ($image && file_exists("blogs/" . $image)) {
            unlink("blogs/" . $image);
        }
        echo 'success';
    } else {
        echo 'error';
    }
}
?>
