-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathheader.php
More file actions
53 lines (51 loc) · 1.29 KB
/
header.php
File metadata and controls
53 lines (51 loc) · 1.29 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();
require_once("connect_db.php");
function product_count($basket)
{
$count = 0;
foreach ($basket as $product)
{
$count += $product["count"];
}
return $count;
}
function total_price()
{
$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'])
$total += $row['price'] * $product["count"];
}
}
}
?>
<div class="navbar">
<a class="active" href="index.php">Home</a>
<div class="dropdown">
<button class="dropbtn">Products</button>
<div class="dropdown-content">
<a href="components.php">Components</a>
<a href="peripherals.php">Peripherals</a>
</div>
</div>
<a class="active" href="basket.php">Basket ( <?= product_count($_SESSION['cart']) ?> )</a>
<div style="float: right">
<?php
if($_SESSION["username"] === "admin") { ?>
<a class="active" href="admin.php">Admin Panel</a> <?php } ?>
<?PHP
if($_SESSION["username"]) { ?>
<a class="active" href="user_settings.php">Hello, <?php echo $_SESSION["username"]; ?></a>
<a class="active" href="logout.php">Log Out</a>
<?PHP }
else { ?>
<a class="active" href="login.php">Log In</a>
<?PHP } ?>
</div>
</div>