Geizkragen/productpage.php
2026-02-11 16:21:27 +01:00

97 lines
2.0 KiB
PHP

<?php include 'header.php'; ?>
<?php
// login.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
session_start();
// 1) DB-Verbindung (einmal)
$servername = "localhost";
$port = 3306;
$username = "FSST";
$password = "L9wUNZZ9Qkbt";
$db = "FSST";
$conn = mysqli_connect($servername, $username, $password, $db, $port);
if (!$conn)
{
http_response_code(500);
die("Datenbankfehler");
}
?>
<?php
$productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
?>
<?php if ($productId <= 0): ?>
<section class="product-section">
<h2>Produkt nicht gefunden</h2>
<p>Bitte eine gueltige Produkt-ID mitgeben.</p>
</section>
<?php else: ?>
<?php
$stmt = $conn->prepare("
SELECT
a.name,
a.unit,
a.dataType,
pa.valueString,
pa.valueNumber,
pa.valueBool
FROM products p
INNER JOIN categoryAttributes ca
ON p.categoryID = ca.categoryID
INNER JOIN attributes a
ON ca.attributeID = a.attributeID
LEFT JOIN productAttributes pa
ON pa.productID = p.productID
AND pa.attributeID = a.attributeID
WHERE p.productID = ?
ORDER BY a.attributeID
");
$stmt->bind_param("i", $productId);
$stmt->execute();
$result = $stmt->get_result();
$product = $result->fetch_assoc();
?>
<?php
while ($row = $result->fetch_assoc()) {
echo "<p><strong>{$row['name']}:</strong> ";
if (!empty($row['valueString'])) echo $row['valueString'];
if (!empty($row['valueNumber'])) echo $row['valueNumber'] . " " . $row['unit'];
if (!is_null($row['valueBool'])) echo $row['valueBool'] ? "Ja" : "Nein";
echo "</p>";
}
?>
<?php $stmt->close(); ?>
<?php endif; ?>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="assets/css/compcard.css">
</head>
<?php include 'footer.php'; ?>