<?php
include 'auth.php';
include '../includes/db.php';
if (isset($_GET['id'])) {
$id = $_GET['id'];
// First, get the image filename to delete it from the server
$stmt = $conn->prepare("SELECT image FROM news WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
$article = $result->fetch_assoc();
if ($article && $article['image']) {
$image_path = '../uploads/news/' . $article['image'];
if (file_exists($image_path)) {
unlink($image_path);
}
}
// Delete the record from the database
$stmt = $conn->prepare("DELETE FROM news WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
header("Location: news.php");
exit;
}
?>