<?php
include('connection.php');

if (isset($_GET['id'])) {
    $PId = $_GET['id'];
    
    // Perform the DELETE operation in your database
    $sql = "DELETE FROM product WHERE id = $PId";
    $result = mysqli_query($conn, $sql);

    if ($result) {
        // Redirect back to the page where Product are displayed with a success message
        header("Location: add_product.php?success=Product deleted successfully.");
        exit();
    } else {
        // Redirect back to the page with an error message if the deletion fails
        header("Location: add_product.php?error=Failed to delete Product.");
        exit();
    }
} else {
    // Handle the case where 'id' is not set in the URL
    header("Location: add_product.php?error=Product ID not provided.");
    exit();
}
?>
