<?php
include("connection.php");

if (!isset($_GET['id'])) {
    die("Invalid Request");
}

$id = (int)$_GET['id']; // Safe type casting

// Validate ID
if ($id <= 0) {
    echo "Invalid Category ID";
    exit;
}

// Delete query
$sql = "DELETE FROM top_categories WHERE id = $id";

if (mysqli_query($con, $sql)) {
    // Redirect back to view
    header("Location: view_top_categories.php");
    exit();
} else {
    echo "Error deleting category: " . mysqli_error($con);
}