prepare($query); $stmt->execute(['memberid' => $memberId]); return $stmt->fetchAll(PDO::FETCH_ASSOC); } // Assuming you store user_id in session and need to get member_id $userId = $_SESSION['userid'] ?? null; if ($userId) { $memberQuery = "SELECT memberid FROM member WHERE userid = :userid"; $stmt = $conn->prepare($memberQuery); $stmt->execute(['userid' => $userId]); $member = $stmt->fetch(PDO::FETCH_ASSOC); $memberId = $member['memberid'] ?? null; } else { // Redirect to login if no user is logged in header('Location: ./Sign&Log.php'); exit(); } // Fetch cart items $cartItems = $memberId ? getCartItems($conn, $memberId) : []; if (isset($_GET['submit']) == 'remove-from-cart') { try { // Delete from cart $deleteQuery = "DELETE FROM cart WHERE memberid = :memberid AND bookid = :bookid"; $deleteStmt = $conn->prepare($deleteQuery); $deleteStmt->execute([ 'memberid' => $member['memberid'], 'bookid' => $_GET['bookid'] ]); header("Location: ./Cart.php"); exit(); } catch (PDOException $e) { error_log("Database error: " . $e->getMessage()); echo "An error occurred while removing the book from your cart."; exit(); } } ?>
Your cart is empty.
By
Publication Year: