Add 404 error handling for invalid product IDs in productpage.php

This commit is contained in:
Fabian Schieder 2026-03-30 19:46:38 +02:00
parent e110b86de2
commit 4bd1286f1c

View File

@ -7,17 +7,24 @@ require_once __DIR__ . '/lib/bootstrap.php';
$conn = db_connect();
$productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
if ($productId <= 0) {
include __DIR__ . '/404.php';
exit;
}
$checkStmt = $conn->prepare("SELECT productID FROM products WHERE productID = ?");
$checkStmt->bind_param("i", $productId);
$checkStmt->execute();
$checkResult = $checkStmt->get_result();
if ($checkResult->num_rows === 0) {
include __DIR__ . '/404.php';
exit;
}
?>
<?php include 'header.php'; ?>
<?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
@ -491,5 +498,4 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
</div>
</div>
<?php endif; ?>
<?php include 'footer.php'; ?>