Implementazione primo prototipo pagina prodotto singolo

This commit is contained in:
2026-04-01 12:22:27 +02:00
parent 52ea1e0c93
commit a5b4ddd655
2 changed files with 100 additions and 0 deletions
+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>
+35
View File
@@ -86,3 +86,38 @@ form button {
form button:hover { form button:hover {
background-color: #218838; 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;
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;
}
}