<?php
require_once "../../config/db.php";

$id = $_GET["id"] ?? null;
if ($id) {
    // First delete related product pages
    $stmt = $pdo->prepare("DELETE FROM product_page WHERE product_id = ?");
    $stmt->execute([$id]);

    // Then delete product
    $stmt = $pdo->prepare("DELETE FROM products WHERE id = ?");
    $stmt->execute([$id]);
}

header("Location: index.php");
exit;
?>