<?php
include 'db.php';

$id = intval($_POST['id'] ?? 0);

if ($id <= 0) {
    echo 0;
    exit;
}

/* optional safety check */
$check = mysqli_query($conn,
    "SELECT COUNT(*) as total FROM products WHERE category_id=$id"
);
$row = mysqli_fetch_assoc($check);

if ($row['total'] > 0) {
    echo 0; // prevent delete if used
    exit;
}

$del = mysqli_query($conn, "DELETE FROM categories WHERE id=$id");

echo $del ? 1 : 0;
