-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmanage_cart.php
58 lines (56 loc) · 1.66 KB
/
manage_cart.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
session_start();
if($_SERVER["REQUEST_METHOD"]=="POST")
{
if(isset($_POST['Add_To_Cart']))
{
if(isset($_SESSION['cart']))
{
$myitems=array_column($_SESSION['cart'], 'Item_Name');
if(in_array($_POST['Item_Name'], $myitems))
{
echo
("<script>
alert('Item Is Already Added');
window.location.href='index.php';
</script>");
}
else
{
$count= count($_SESSION['cart']);
$_SESSION['cart'][$count]=array('Item_Name'=> $_POST['Item_Name'], 'Price'=> $_POST['Price'], 'Quantity'=>1);
echo
("<script>
alert('Item Added');
window.location.href='index.php';
</script>");
}
}
else
{
$_SESSION['cart'][0]=array('Item_Name'=> $_POST['Item_Name'], 'Price'=> $_POST['Price'], 'Quantity'=>1);
echo
("<script>
alert('Item Added');
window.location.href='index.php';
</script>");
}
}
if(isset($_POST['Remove_Item']))
{
foreach($_SESSION['cart'] as $key => $value)
{
if($value['Item_Name']== $_POST['Item_Name'])
{
unset($_SESSION['cart'][$key]);
$_SESSION['cart']=array_values($_SESSION['cart']);
echo"
<script>
alert('Item Removed');
window.location.href='shoppingcart.php';
</script>";
}
}
}
}
?>