-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-cart.php
More file actions
45 lines (26 loc) · 775 Bytes
/
update-cart.php
File metadata and controls
45 lines (26 loc) · 775 Bytes
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
<?php
//if (session_status() !== PHP_SESSION_ACTIVE) {session_start();}
if(session_id() == '' || !isset($_SESSION)){session_start();}
include 'config.php';
$product_id = $_GET['id'];
$action = $_GET['action'];
if($action === 'empty')
unset($_SESSION['cart']);
$result = $mysqli->query("SELECT qty FROM products WHERE id = ".$product_id);
if($result){
if($obj = $result->fetch_object()) {
switch($action) {
case "add":
if($_SESSION['cart'][$product_id]+1 <= $obj->qty)
$_SESSION['cart'][$product_id]++;
break;
case "remove":
$_SESSION['cart'][$product_id]--;
if($_SESSION['cart'][$product_id] == 0)
unset($_SESSION['cart'][$product_id]);
break;
}
}
}
header("location:cart.php");
?>