<?php
include("koneksi.php");

if ($_SERVER["REQUEST_METHOD"] == "GET") {
    if (isset($_GET['product_id'])) {
        
        $id = intval($_GET['product_id']);

        $sql = "DELETE FROM products WHERE product_id = $id";
        $hasil = mysqli_query($conn, $sql);

        if ($hasil) {
            echo "<script>
                alert('Produk dengan ID $id berhasil dihapus!');
                window.location.href = '../produk.php';
            </script>";
        } else {
            echo "<script>
                alert('Gagal menghapus produk!');
                window.history.back();
            </script>";
        }
    } else {
        echo "<script>
            alert('ID produk tidak ditemukan!');
            window.history.back();
        </script>";
    }
} else {
    header("Location: ../Produk/produk.php");
    exit();
}
?>
