From 4575b92e68b1fd073774bf090babf817dede05dc Mon Sep 17 00:00:00 2001 From: Fabian Schieder Date: Tue, 7 Apr 2026 19:16:19 +0200 Subject: [PATCH] Refactor productpage to use LEFT JOINs for category and attribute tables, add error handling for missing products, and improve output formatting for product attributes --- productpage.php | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/productpage.php b/productpage.php index bf49ab3..12dc47b 100644 --- a/productpage.php +++ b/productpage.php @@ -98,10 +98,10 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_review']) && i p.categoryID FROM products p - INNER JOIN categoryAttributes ca + LEFT JOIN categoryAttributes ca ON p.categoryID = ca.categoryID - INNER JOIN attributes a + LEFT JOIN attributes a ON ca.attributeID = a.attributeID LEFT JOIN productAttributes pa @@ -119,6 +119,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_review']) && i $result = $stmt->get_result(); $product = $result->fetch_assoc(); + if (!$product) { + die("Produkt nicht gefunden."); + } $categoryId = $product['categoryID']; /** @@ -357,7 +360,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
- +
{$product['name']}: "; + if (!empty($product['valueString'])) echo htmlspecialchars($product['valueString']); + if (!empty($product['valueNumber'])) echo htmlspecialchars($product['valueNumber'] . " " . $product['unit']); + if (!is_null($product['valueBool'])) echo $product['valueBool'] ? "Ja" : "Nein"; + echo "

"; + } while ($row = $result->fetch_assoc()) { + if (empty($row['name'])) continue; echo "

{$row['name']}: "; - if (!empty($row['valueString'])) echo $row['valueString']; - if (!empty($row['valueNumber'])) echo $row['valueNumber'] . " " . $row['unit']; + if (!empty($row['valueString'])) echo htmlspecialchars($row['valueString']); + if (!empty($row['valueNumber'])) echo htmlspecialchars($row['valueNumber'] . " " . $row['unit']); if (!is_null($row['valueBool'])) echo $row['valueBool'] ? "Ja" : "Nein"; echo "

"; }