-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckAddToCart.php
38 lines (29 loc) · 1.11 KB
/
checkAddToCart.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
<?php
require_once __DIR__. "/autoload/autoload.php";
if(!isset($_SESSION['email']))
{
header("Location: http://localhost/fruitstore/loginForm.php");
$_SESSION['fail'] = "Please login first !";
}
else
{
$id = intval(getInput('id'));
//get products
$product = $db->fetchID('products', $id);
if(! isset($_SESSION['cart'][$id]))
{
//new cart
$_SESSION['cart'][$id]['name'] = $product['name'];
$_SESSION['cart'][$id]['image'] = $product['image'];
$_SESSION['cart'][$id]['price'] = $product['price'];
$_SESSION['cart'][$id]['quantity'] = 1;
header("Location: http://localhost/fruitstore/addCart.php?id=$id");
}
else
{
//add to cart
$_SESSION['cart'][$id]['quantity'] += 1;
header("Location: http://localhost/fruitstore/addCart.php?id=$id");
}
}
?>