-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddToCartProcess.php
44 lines (33 loc) · 1.25 KB
/
addToCartProcess.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
43
44
<?php
session_start();
include "connection.php";
if(isset($_SESSION["u"])){
if(isset($_GET["id"])){
$pid = $_GET["id"];
$umail = $_SESSION["u"]["email"];
$cart_rs = Database::search("SELECT * FROM `cart` WHERE `product_id`='".$pid."' AND `user_email`='".$umail."'");
$cart_num = $cart_rs->num_rows;
$product_rs = Database::search("SELECT * FROM `product` WHERE `id`='".$pid."'");
$product_data = $product_rs->fetch_assoc();
$product_qty = $product_data["qty"];
if($cart_num == 1){
$cart_data = $cart_rs->fetch_assoc();
$current_qty = $cart_data["qty"];
$new_qty = (int)$current_qty + 1;
if($product_qty >= $new_qty){
Database::iud("UPDATE `cart` SET `qty`='".$new_qty."' WHERE `cart_id`='".$cart_data["cart_id"]."'");
echo ("Cart updated");
}else{
echo ("Invalid Quantity");
}
}else{
Database::iud("INSERT INTO `cart`(`qty`,`user_email`,`product_id`) VALUES ('1','".$umail."','".$pid."')");
echo ("New product added to the cart.");
}
}else{
echo ("Someting Went Wrong.");
}
}else{
echo ("Please Login or Signup first.");
}
?>