-
Notifications
You must be signed in to change notification settings - Fork 0
/
carrello.php
45 lines (40 loc) · 1.13 KB
/
carrello.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
<?php
include 'database.php';
$sql = "SELECT id, name, price FROM products";
$result = $conn->query($sql);
$products = [];
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
$products[] = $row;
}
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Carrello della Spesa</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<h1>Prodotti</h1>
<div class="products">
<?php foreach ($products as $product): ?>
<div class="product">
<h2><?php echo $product['name']; ?></h2>
<p>Prezzo: €<?php echo number_format($product['price'], 2); ?></p>
<button onclick="addToCart(<?php echo $product['id']; ?>)">Aggiungi al carrello</button>
</div>
<?php endforeach; ?>
</div>
<h1>Carrello</h1>
<div id="cart">
<p>Il carrello è vuoto.</p>
</div>
<script>
const products = <?php echo json_encode($products); ?>;
</script>
<script src="script.js"></script>
</body>
</html>