<?php
include "database/database.php";
include "database/data.php";
session_start();

if (isset($_SESSION['browser_id'])) {
    $browserId = $_SESSION['browser_id'];
} else {
    // Generate a new browser ID
    $browserId = generateUniqueBrowserId();

    // Store the browser ID in the session for future use
    $_SESSION['browser_id'] = $browserId;
}

$b_id = $browserId;


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $productName = $_POST['product_name'] ?? null;

    if ($productName) {

    
        $query = "DELETE FROM " . $product . " WHERE product_name = '$productName'";
        $connection->query($query);

        $query = "DELETE FROM " . $cargo_1 . " WHERE product_name = '$productName'";
        $connection->query($query);
   
        
    } else {
        http_response_code(400); // Bad request
        echo "Error: Product name is required.";
    }
}


function generateUniqueBrowserId()
{
    $randomString = bin2hex(random_bytes(16));
    $timestamp = time();

    return $randomString . $timestamp;
}
