<?php
session_start();
include 'koneksi.php'; 

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

if (isset($_GET['id'])) {
    $id = $_GET['id'];
    $sql = "DELETE FROM riwayat_barang WHERE id = ?";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("i", $id);

    if ($stmt->execute()) {
        header("Location: riwayat_barang.php?message=success");
        exit();
    } else {
        header("Location: riwayat_barang.php?message=error");
        exit();
    }
} else {
    header("Location: riwayat_barang.php");
    exit();
}
if (isset($_GET['message'])) {
    if ($_GET['message'] == 'success') {
        echo "<div class='alert alert-success'>Riwayat berhasil dihapus.</div>";
    } elseif ($_GET['message'] == 'error') {
        echo "<div class='alert alert-danger'>Terjadi kesalahan saat menghapus riwayat.</div>";
    }
}


?>
