<?php
session_start();
if (!isset($_SESSION['admin_logged_in']) || $_SESSION['admin_logged_in'] !== true) {
    header('Location: index.php');
    exit;
}
require 'dbconn.php';

// Check if ID is passed via GET
if (isset($_GET['id'])) {
    $id = intval($_GET['id']);

    // Prepare and execute delete query
    $query = "DELETE FROM news_tb WHERE id = ?";
    $stmt = $mysqli->prepare($query);
    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        // Redirect back to manage page with success message
        header("Location: manage_news.php?deleted=1");
        exit;
    } else {
        echo "Error deleting record: " . $stmt->error;
    }

    $stmt->close();
} else {
    echo "Invalid request.";
}
?>
