<?php
session_start();

include 'db.php';

if (!isset($_SESSION['username'])) {
    header("Location: login.php");
    exit;
}

$email = $_SESSION['username'];

$conn = new mysqli($servername, $username, $password, $database);

if ($conn->connect_error) {
    echo "Gagal : " . $conn->error;
}

$stmt = $conn->prepare("SELECT no_id FROM pelanggan WHERE Email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->bind_result($no_plg);
$stmt->fetch();
$stmt->close();

$stmt = $conn->prepare("DELETE FROM transaksi WHERE no_plg = ? AND Invoice IS NULL");
$stmt->bind_param("i", $no_plg);

if ($stmt->execute()) {
    echo "Berhasil Mengosongkan Keranjang Belanja!";
}





$stmt->close();
$conn->close();



?>

