-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinsertbag.php
More file actions
53 lines (43 loc) · 1.39 KB
/
insertbag.php
File metadata and controls
53 lines (43 loc) · 1.39 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
48
49
50
51
52
53
<?php
session_start();
if(isset($_POST['addCart'])){
$product_name = $_POST['PName'];
$product_price = $_POST['PPrice'];
$product_image = $_POST['Image'];
$product_price2 = $_POST['PPrice2'];
$_SESSION['cart'][] = array(
'productName' => $product_name,
'productPrice' => $product_price,
'productImage' => $product_image,
'productPrice2' => $product_price2,
);
header("location:index.php");
}
//this function is to remove a selected item
if(isset($_POST['remove'])){
$item_to_remove = $_POST['item'];
foreach($_SESSION['cart'] as $key => $value){
if($value['productName'] === $item_to_remove){
unset($_SESSION['cart'][$key]);
$_SESSION['cart'] = array_values($_SESSION['cart']);
header('location:bag.php');
}
}
}
if(isset($_POST['update'])){
$item_to_update = $_POST['item'];
$product_name = $_POST['Pname'];
$product_price = $_POST['PPrice'];
$product_image = $_POST['Image'];
foreach($_SESSION['cart'] as $key => $value){
if($value['productName'] === $item_to_update){
$_SESSION['cart'][$key] = array(
'productName' => $product_name,
'productPrice' => $product_price,
'productImage' => $product_image,
);
header("location:bag.php");
}
}
}
?>