-
Notifications
You must be signed in to change notification settings - Fork 3
/
add-to-cart.php
42 lines (32 loc) · 1.19 KB
/
add-to-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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
session_start();
include('dbconnect.php');
if (isset($_POST['cusID']) && isset($_POST['resID']) && isset($_POST['foodID']) && isset($_POST['price']) && isset($_POST['quantity'])) {
$cusID = $_POST['cusID'];
$resID = $_POST['resID'];
$foodID = $_POST['foodID'];
$price = $_POST['price'];
$quantity = $_POST['quantity'];
$check = "SELECT count(*) as countdata
FROM cart
WHERE cusID='$cusID' AND resID='$resID' AND foodID='$foodID'";
$check = mysqli_query($connection, $check);
$check = mysqli_fetch_all($check, MYSQLI_ASSOC);
if ($check[0]['countdata'] == 0) {
if ($quantity>0){
$sql = "INSERT IGNORE INTO cart (cusID, resID, foodID, price, quantity)
VALUES ('$cusID', '$resID', '$foodID', '$price', '$quantity')";
$stmt = mysqli_query($connection, $sql);
header("Location: menu.php?message=Item added to cart successfully!&resID=$resID");
exit;
}
else{
header("Location: menu.php?message=Invalid Amount&resID=$resID");
exit;
}
}
else{
header("Location: menu.php?resID=$resID&message=Item already exists in cart!!");
exit;
}
}