-
Notifications
You must be signed in to change notification settings - Fork 0
/
shop.php
executable file
·57 lines (56 loc) · 1.52 KB
/
shop.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
<?php
session_start();
$connect = mysqli_connect("localhost", "root", "", "m");
if(isset($_POST["add"]))
{
if(isset($_SESSION["cart"]))
{
$item_array_id = array_column($_SESSION["cart"], "product_id");
if(!in_array($_GET["id"], $item_array_id))
{
$count = count($_SESSION["cart"]);
$item_array = array(
'product_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'product_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["cart"][$count] = $item_array;
header("Location: product_page.php?added=success");
}
else
{
// echo '<script>alert("Products already added to cart")</script>';
// echo '<script>window.location="index.php"</script>';
header("Location: product_page.php?entry_already=success");
}
}
else
{
$item_array = array(
'product_id' => $_GET["id"],
'item_name' => $_POST["hidden_name"],
'product_price' => $_POST["hidden_price"],
'item_quantity' => $_POST["quantity"]
);
$_SESSION["cart"][0] = $item_array;
header("Location: product_page.php?added=success");
}
}
if(isset($_GET["action"]))
{
if($_GET["action"] == "delete")
{
foreach($_SESSION["cart"] as $keys => $values)
{
if($values["product_id"] == $_GET["id"])
{
unset($_SESSION["cart"][$keys]);
// echo '<script>alert("Product has been removed")</script>';
// echo '<script>window.location="index.php"</script>';
header("Location: product_page.php?del=success");
}
}
}
}
?>