-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
90 lines (64 loc) · 2.67 KB
/
index.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
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
<?php
// start session
session_start();
require_once('./php/CreateDb.php');
require_once('./php/component.php');
// Create instance of CreateDb class
$database = new CreateDb("ProductDb","ProductTb");
if(isset($_POST['add']))
if(isset($_SESSION['cart'])){
$item_array_id = array_column($_SESSION['cart'],'product_id');
/* kollar om varan redan finns i varukorgen när man lägger i kundvagn */
if(in_array($_POST['product_id'], $item_array_id)){
echo '<script>alert("Produkten finns redan i varukorgen...");</script>';
}else{
$count = count($_SESSION['cart']);
$item_array = array(
'product_id' => $_POST['product_id']
);
$_SESSION['cart'][$count] = $item_array;
}
}else{
$item_array = array(
'product_id' => $_POST['product_id']
);
// Create new session variable
$_SESSION['cart'][0] = $item_array;
print_r($_SESSION['cart']);
}
?>
<!DOCTYPE html>
<html lang="Sv">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- importing bootstrap css -->
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
<!-- Importing font-awesome for icons -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css" integrity="sha512-Fo3rlrZj/k7ujTnHg4CGR2D7kSs0v4LLanw2qksYuRlEzO+tcaEPQogQ0KaoGN26/zrn20ImR1DfuLWnOo7aBA==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<!-- importing css-file -->
<link rel="stylesheet" href="style.css">
<title>Emanuel's Webshop</title>
</head>
<body>
<!-- Importing navigation bar -->
<?php
require_once ("php/header.php")
?>
<!-- product card holder -->
<div class="container">
<div class="row text-center py-5">
<?php
// anropar component-funktionen med produktkortet
$result = $database->getData();
while ($row = mysqli_fetch_assoc($result)){
component($row['product_name'], $row['product_description'], $row['product_price'], $row['product_image'], $row['id']);
}
?>
</div>
</div>
<!-- importing bootstrap JavaScript-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" crossorigin="anonymous"></script>
</body>
</html>