-
Notifications
You must be signed in to change notification settings - Fork 0
/
cannabis.php
95 lines (87 loc) · 4.22 KB
/
cannabis.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
91
92
93
94
95
<!doctype html>
<html lang="en">
<style>
hr.new
{
border: 3px solid blueviolet;
}
</style>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>CANNABIS</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-aFq/bzH65dt+w6FI2ooMVUpc+21e0SRygnTpmBvdBgSdnuTN7QbdgL+OapgHtvPp" crossorigin="anonymous">
<center>
<img style="margin-top: 20px;" src="img/joint (1).png"><br><br>
<hr class="new" style="color: blueviolet; width: 80%;">
</head>
<body style="background-color: #000000e0;">
<form method="POST" action=" <?php $_SERVER["PHP_SELF"]; ?> ">
<div class="row row-cols-1 row-cols-md-3 g-4">
<?php
// Connessione al database
include('config/db.php');
// Query per recuperare i dati dei prodotti dalla tabella 'product'
$query = "SELECT * FROM products WHERE id=1;";
// Esecuzione della query
$result = mysqli_query($connection, $query);
// Recupero dei dati e creazione dei card per ogni prodotto
while ($row = mysqli_fetch_assoc($result))
{
echo '
<div class="col" style="margin-left:190px; margin-top: 30px;">
<div class="card h-100" style="width: 30rem; margin-top: 30px; background-color:#000000e0; border-color: blueviolet;">
<img src="img/amnesia.png" class="card-img-top" alt="...">
<div class="card-body">
<center>
<h5 class="card-title" style="color: aliceblue;">' . $row['ProductName'] . '</h5>
<form method="post" action = "{$_SERVER["PHP_SELF"]}">
<input class="btn btn-primary" type="number" style="background-color: blueviolet; border-color: blueviolet;" name="quantity">
<input type="hidden" name="productname" value="' . $row['ProductName'] . '">
<input type="hidden" name="ID" value="' . $row['ID'] . '">
<input type="hidden" name="ShopID" value="' . $row['ShopID'] . '">
<input type="hidden" name="price" value="' . $row['Price'] . '">
<input class="btn btn-primary" type="submit" style="background-color: blueviolet; border-color: blueviolet;" value="Aggiungi al carrello" name="add">
</form>
</center>
</div>
</div>
</div>
';
}
mysqli_close($connection);
?>
</div>
<br><br><br><a href="index.html" style="color: blueviolet; font-family: monospace; font-size: 20px;">PAGINA INIZIALE</a>
<a href="cart.php" style="color: blueviolet; font-family: monospace; font-size: 20px;">CARRELLO</a>
</center>
</form>
</body>
</html>
<!-- Pagina di gestione del carrello (gestione_carrello.php) -->
<?php
// Connessione al database
include('config/db.php');
// Verifica se è stato inviato un comando di aggiunta al carrello
if (isset($_POST['add']) ) {
// Recupera i dati del prodotto dal form
/*+-------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------------+--------------+------+-----+---------+-------+
| price | float | NO | | NULL | |
| quantity | int(11) | NO | | NULL | |
| productname | varchar(255) | NO | | NULL | |
| ProductID | int(11) | YES | | NULL | |
| ShopID | int(11) | YES | | NULL | |
| CustomerID | int(11) | YES | | NULL | |
+-------------+--------------+------+-----+---------+-------+ */
$productname = $_POST['productname'];
$price = $_POST['price'];
$quantity=$_POST['quantity'];
$ShopID=$_POST['ShopID'];
$ProductID=$_POST['ID'];
// Inserisci i dati del prodotto nella tabella "cart"
$query = "INSERT INTO cart (productname, price, quantity,ProductID,ShopID) VALUES ('$productname', $price, $quantity,$ProductID,$ShopID);";
mysqli_query($connection, $query);
}
?>