-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcheck_cart.php
27 lines (24 loc) · 994 Bytes
/
check_cart.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
require 'config.php';
session_start();
// Check if a book is being added to the cart
if (isset($_GET['book_id'])) {
$bookID = $_GET['book_id'];
$uname = $_SESSION["usename"];
// Check if the book is already in the cart
$sqlCheck = "SELECT * FROM cart WHERE c_name = '$uname' AND book_id = '$bookID'";
$resultCheck = $conn->query($sqlCheck);
if ($resultCheck->num_rows > 0) {
// Book already exists in the cart
echo "<script>alert('This book is already in your cart.')</script>";
} else {
// Book is not in the cart, add it
$sqlAdd = "INSERT INTO cart (c_name, book_id) VALUES ('$uname', '$bookID')";
if ($conn->query($sqlAdd) === TRUE) {
echo "<script>alert('Book added to cart successfully.')</script>";
} else {
echo "<script>alert('Failed to add book to cart.')</script>";
}
}
}
?>