<?php
require '../config.php';
session_start();

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

$id = $_GET['id'];
$user_id = $_SESSION['user_id'];

// Cek apakah item milik user
$cek = mysqli_query($conn, "SELECT * FROM keranjang WHERE id=$id AND pengguna_id=$user_id");
if (mysqli_num_rows($cek) > 0) {
  mysqli_query($conn, "DELETE FROM keranjang WHERE id=$id");
}

header("Location: keranjang.php");
