-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasket.php
More file actions
99 lines (97 loc) · 2.96 KB
/
basket.php
File metadata and controls
99 lines (97 loc) · 2.96 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?PHP
session_start();
if (isset($_POST["remove"]) && isset($_GET['id']))
{
unset($_SESSION["cart"][$_GET["id"]]);
}
if (isset($_POST["decrease"]) && isset($_GET['id']))
{
if ($_SESSION["cart"][$_GET["id"]]["count"] > 1)
$_SESSION["cart"][$_GET["id"]]["count"] -= 1;
}
if (isset($_POST["increase"]) && isset($_GET['id']))
{
if ($_SESSION["cart"][$_GET["id"]]["count"] < 99)
$_SESSION["cart"][$_GET["id"]]["count"] += 1;
}
?>
<?PHP require_once("connect_db.php") ?>
<html>
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="css/basket.css">
<link rel="stylesheet" href="css/nav.css">
<title>Basket</title>
</head>
<body>
<?PHP require("header.php") ?>
<div class="holder">
<div class="container">
<h2 style="width: 10vw">The Basket</h2>
<div>
<?PHP
if (isset($_SESSION["cart"]) && count($_SESSION["cart"]) != 0)
{
$sql = "SELECT * FROM products";
$result = mysqli_query($con, $sql);
while ($row = mysqli_fetch_assoc($result))
{
foreach ($_SESSION["cart"] as $product)
{
/* print($product); */
if ($_POST["count"])
$product["count"] = $_POST["count"];
if ($row['id'] == $product['product_id'])
{
?>
<form action="basket.php?id=<?= $row['id'] ?>" method="POST" class="items">
<div class="product_div">
<h4><?=$row['title']; ?></h4>
<img class="product_image" src="<?= $row['image']; ?>" alt="<?= $row['title']; ?>" />
<p>Price: <?= $row['price']; ?>€</p>
<div class="button-div">
<button type="submit" class="button" name="decrease" style="width: 1.5vw">-</button>
<input type="button" class="button" name="count" value="<?= $product["count"] ?>" style="width: 1.5vw" \>
<button type="submit" class="button" name="increase" style="width: 1.5vw">+</button>
<button type="submit" class="button" name="remove" style="margin-left: 0.5vw">Remove</button>
</div>
</div>
</form>
<?PHP
}
}
}
}
else
echo '<h5 style="color: white;">Basket is Empty</h5>';
?>
</div>
</div>
<div class="summary">
<h2>Summary</h2>
<?PHP
$sql = "SELECT * FROM products";
$result = mysqli_query($con, $sql);
$total = 0;
while ($row = mysqli_fetch_assoc($result))
{
foreach ($_SESSION["cart"] as $product)
{
if ($row['id'] == $product['product_id'])
{ ?>
<p style="color: white; margin-left: 1vw;"><?=$row['title']; ?> ( x <?= $product["count"] ?> ) : <?= number_format($row['price'] * $product["count"], 2, '.', '') ?>€</p>
<?PHP $total += $row['price'] * $product["count"];
}
}
}
?>
<h2>Total: <?= number_format($total, 2, '.', ''); ?>€</h2>
<?PHP if ($total != 0) { ?>
<form method="POST" action="checkout.php">
<button type="submit" class="checkout" name="submit" >Checkout</button>
</form>
<?PHP } ?>
</div>
</div>
</body>
</html>