-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddToCartProcess.php
More file actions
47 lines (33 loc) · 1.26 KB
/
addToCartProcess.php
File metadata and controls
47 lines (33 loc) · 1.26 KB
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
45
46
47
<?php
session_start();
require "includes/connection.php";
if(isset($_SESSION["u"])){
if(isset($_GET["id"])){
$email = $_SESSION["u"]["email"];
$pid = $_GET["id"];
$cart_rs = Database::search("SELECT*FROM `cart`WHERE `product_id`='".$pid."'AND `user_email`='".$email."'");
$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 `product_id`='".$pid."' AND `user_email`='".$email."'");
echo("Product Updated");
}else{
echo("Invalid quantity");
}
}else{
Database::iud("INSERT INTO `cart`(`product_id`,`user_email`,`qty`)VALUES ('".$pid."','".$email."','1')");
echo ("Product added successfully");
}
}else{
echo("Something Went Wrong");
}
}else{
echo ("Please Sign In or Register.");
}
?>