Implementazione pagina prodotto

This commit is contained in:
2026-04-01 12:41:22 +02:00
3 changed files with 119 additions and 2 deletions
+2 -2
View File
@@ -37,8 +37,8 @@ if ($result === false) {
<div class="products-grid">
<?php while ($row = $result->fetch_assoc()): ?>
<div class="product-card">
<img src="img/<?php echo htmlspecialchars($row['ImagePath']); ?>" alt="Immagine prodotto">
<h3><?php echo htmlspecialchars($row['ProductName']); ?></h3>
<a href="product.php?id=<?php echo $row['ProductID']; ?>"><div class="img-square"><img src="img/<?php echo htmlspecialchars($row['ImagePath']); ?>" alt="Immagine prodotto"></div></a>
<h3><?php echo "<a href='product.php?id=" . $row['ProductID'] . "'>" . htmlspecialchars($row['ProductName']) . "</a>"; ?></h3>
<p><?php echo htmlspecialchars($row['Price']); ?>€</p>
<button>Aggiungi al carrello</button>
</div>
+65
View File
@@ -0,0 +1,65 @@
<?php
session_start();
include 'db_conf.php';
// Ottieni l'ID del prodotto dall'URL
$product_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
// Query per ottenere il singolo prodotto
$sql = "SELECT p.ProductID, p.ProductName, c.Name AS 'CategoryName', p.Description, p.Price, p.StockQuantity, p.ImagePath FROM Products p JOIN Categories c ON p.CategoryID=c.CategoryID WHERE p.ProductID = ?";
if ($stmt = $conn->prepare($sql)) {
$stmt->bind_param("i", $product_id);
$stmt->execute();
$result = $stmt->get_result();
$product = $result->fetch_assoc();
$stmt->close();
} else {
die("Errore nella query: " . $conn->error);
}
?>
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php if ($result->num_rows > 0): ?>
<title>TechStore - <?php echo htmlspecialchars($result->fetch_assoc()['CategoryName']); ?></title>
<?php else: ?>
<title>Prodotto non trovato - TechStore</title>
<?php endif; ?>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header style="display: flex; justify-content: space-between; align-items: center; padding: 10px; background-color: #f2f2f2; border-bottom: 1px solid #ddd;">
<div id="logo" style="font-size: 24px; font-weight: bold;"><a href="index.php">TechStore</a></div>
<div>
<a href=""><button style="margin-left: 10px; padding: 8px 16px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer;">Carrello</button></a>
<?php if (isset($_SESSION['user'])): ?>
<a href="logout.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #dc3545; color: white; border: none; border-radius: 4px; cursor: pointer;">Logout</button></a>
<span style="margin-left: 10px;">Benvenuto, <?php echo htmlspecialchars($_SESSION['user']); ?></span>
<?php else: ?>
<a href="login.php"><button style="margin-left: 10px; padding: 8px 16px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Accesso</button></a>
<?php endif; ?>
</div>
</header>
<?php if ($product): ?>
<div class="product-detail">
<img src="img/<?php echo htmlspecialchars($product['ImagePath']); ?>" alt="Immagine prodotto">
<div>
<h1><?php echo htmlspecialchars($product['ProductName']); ?></h1>
<p><strong>Categoria:</strong> <?php echo htmlspecialchars($product['CategoryName']); ?></p>
<p><strong>Descrizione:</strong> <?php echo htmlspecialchars($product['Description']); ?></p>
<p><strong>Prezzo:</strong> €<?php echo htmlspecialchars($product['Price']); ?></p>
<p><strong>Quantità disponibile:</strong> <?php echo htmlspecialchars($product['StockQuantity']); ?></p>
<button style="padding: 10px 20px; background-color: #28a745; color: white; border: none; border-radius: 4px; cursor: pointer;">Aggiungi al carrello</button>
</div>
</div>
<?php else: ?>
<p style="text-align: center; margin: 50px;">Prodotto non trovato.</p>
<?php endif; ?>
<?php $conn->close(); ?>
</body>
</html>
+52
View File
@@ -88,4 +88,56 @@ form button {
form button:hover {
background-color: #218838;
}
/* Stili per la pagina prodotto */
.product-detail {
max-width: 800px;
margin: 20px auto;
padding: 20px;
border: 1px solid #ddd;
border-radius: 8px;
background-color: #fff;
display: flex;
flex-direction: column;
}
.product-detail img {
max-width: 100%;
height: auto;
object-fit: contain;
margin-bottom: 20px;
flex-shrink: 0;
}
.product-detail > div {
flex: 1;
}
@media (min-width: 768px) {
.product-detail {
flex-direction: row;
}
.product-detail img {
max-width: 40%;
margin-bottom: 0;
margin-right: 20px;
}
}
.img-square {
position: relative;
width: 100%;
padding-top: 100%; /* crea un quadrato perfetto */
overflow: hidden;
}
.img-square img {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
object-fit: contain; /* o "cover" */
}