From 4bd1286f1cb5cd80f884c605ffbc69282bf34fab Mon Sep 17 00:00:00 2001 From: Fabian Schieder Date: Mon, 30 Mar 2026 19:46:38 +0200 Subject: [PATCH] Add 404 error handling for invalid product IDs in productpage.php --- productpage.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/productpage.php b/productpage.php index 1501ea0..072db54 100644 --- a/productpage.php +++ b/productpage.php @@ -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; +} ?> - -
-

Produkt nicht gefunden

-

Bitte eine gueltige Produkt-ID mitgeben.

-
- - prepare(" SELECT @@ -491,5 +498,4 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0; - \ No newline at end of file