<?php
include 'db.php';
session_start();
if (!isset($_SESSION['user'])) {
    echo "Login first!";
    exit;
}
$id = $_GET['id'];
$email = $_SESSION['email'];
$result = mysqli_query($conn, "SELECT * FROM image WHERE id='$id' AND user_email='$email'");
if (mysqli_num_rows($result) == 1) {
    $row = mysqli_fetch_assoc($result);
    unlink('uploads/' . $row['filename']);
    mysqli_query($conn, "DELETE FROM image WHERE id='$id'");
    echo "Deleted successfully! <a href='display.php'>Back</a>";
} else {
    echo "Unauthorized delete!";
}
?>