From 701245fafcc2e95b658a5b71e2d5452529fa0cc4 Mon Sep 17 00:00:00 2001 From: fsst Date: Wed, 18 Mar 2026 15:34:07 +0100 Subject: [PATCH 1/3] Review adder JavaS fix --- productpage.php | 92 ++++++++++++++++++++++++------------------------- 1 file changed, 45 insertions(+), 47 deletions(-) diff --git a/productpage.php b/productpage.php index 19ef8c6..77eb185 100644 --- a/productpage.php +++ b/productpage.php @@ -369,52 +369,48 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0; - = 1 && $rating <= 5 && !empty($comment)) { - - // SQL-Statement vorbereiten (wie im Screenshot: userID, productID, rating, comment) - $stmtInsertRev = mysqli_prepare( - $conn, - "INSERT INTO reviews (userID, productID, rating, comment) VALUES (?, ?, ?, ?)" - ); - - if ($stmtInsertRev) { - // "iiis" steht für: Integer, Integer, Integer, String - mysqli_stmt_bind_param( - $stmtInsertRev, - "iiis", - $userID, - $productId, - $rating, - $comment - ); - - mysqli_stmt_execute($stmtInsertRev); - mysqli_stmt_close($stmtInsertRev); - - // WICHTIG: Die Seite neu laden, damit das Formular bei einem Refresh (F5) nicht doppelt gesendet wird - header("Location: productpage.php?id=" . $productId); - exit; // Stoppt das Skript hier, da wir weiterleiten - } - } - } - ?> -

Füge deine Bewertung hinzu!

+ = 1 && $rating <= 5 && !empty($comment)) { + + $stmtInsertRev = mysqli_prepare( + $conn, + "INSERT INTO reviews (userID, productID, rating, comment) VALUES (?, ?, ?, ?)" + ); + + if ($stmtInsertRev) { + mysqli_stmt_bind_param( + $stmtInsertRev, + "iiis", + $userID, + $productId, + $rating, + $comment + ); + + mysqli_stmt_execute($stmtInsertRev); + mysqli_stmt_close($stmtInsertRev); + + // TRICK: JavaScript-Weiterleitung anstelle von PHP-Header! + echo ""; + exit; + } + } + } + ?> +
@@ -443,10 +439,12 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
-

Du musst eingeloggt sein, um eine Bewertung abzugeben.

- - - +
From 9a3cdd975a042a86a0e00dd9b11253779a63bc10 Mon Sep 17 00:00:00 2001 From: fsst Date: Wed, 18 Mar 2026 15:39:15 +0100 Subject: [PATCH 2/3] Review adder made limit 1 review per user --- productpage.php | 120 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 92 insertions(+), 28 deletions(-) diff --git a/productpage.php b/productpage.php index 02767af..82b1dd9 100644 --- a/productpage.php +++ b/productpage.php @@ -400,43 +400,107 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0; } ?> -
- -
- +
+

Füge deine Bewertung hinzu!

-
- - + - + // 1. Prüfen, ob der eingeloggte Nutzer schon bewertet hat + if (isset($_SESSION['user_id'])) { + $stmtCheckRev = mysqli_prepare($conn, "SELECT 1 FROM reviews WHERE userID = ? AND productID = ? LIMIT 1"); + mysqli_stmt_bind_param($stmtCheckRev, "ii", $_SESSION['user_id'], $productId); + mysqli_stmt_execute($stmtCheckRev); + mysqli_stmt_store_result($stmtCheckRev); - - + if (mysqli_stmt_num_rows($stmtCheckRev) > 0) { + $userHasReviewed = true; + } + mysqli_stmt_close($stmtCheckRev); + } - - + // 2. Bewertung speichern (NUR wenn noch keine existiert!) + if ( + $_SERVER['REQUEST_METHOD'] === 'POST' && + isset($_POST['submit_review']) && + isset($_SESSION['user_id']) && + !$userHasReviewed + ) { + $rating = (int)$_POST['rating']; + $comment = trim($_POST['comment']); + $userID = $_SESSION['user_id']; - - + if ($rating >= 1 && $rating <= 5 && !empty($comment)) { + + $stmtInsertRev = mysqli_prepare( + $conn, + "INSERT INTO reviews (userID, productID, rating, comment) VALUES (?, ?, ?, ?)" + ); + + if ($stmtInsertRev) { + mysqli_stmt_bind_param( + $stmtInsertRev, + "iiis", + $userID, + $productId, + $rating, + $comment + ); + + mysqli_stmt_execute($stmtInsertRev); + mysqli_stmt_close($stmtInsertRev); + + // JS Weiterleitung + echo ""; + exit; + } + } + } + ?> + +
+ + - + + - - - - - + +
+ + +
+ + + + + + + + + + + + + + +
+ + + + +
+ +
-
From cf7d60708ef14e091a107db70d5008135fe2b902 Mon Sep 17 00:00:00 2001 From: fsst Date: Wed, 18 Mar 2026 15:43:27 +0100 Subject: [PATCH 3/3] Review adder made limit 1 review per user --- productpage.php | 144 +++++++++++++++++------------------------------- 1 file changed, 51 insertions(+), 93 deletions(-) diff --git a/productpage.php b/productpage.php index 82b1dd9..47a10a6 100644 --- a/productpage.php +++ b/productpage.php @@ -362,11 +362,27 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;

Füge deine Bewertung hinzu!

0) { + $userHasReviewed = true; + } + mysqli_stmt_close($stmtCheckRev); + } + + // 2. Bewertung speichern (NUR wenn noch keine existiert!) if ( $_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit_review']) && - isset($_SESSION['user_id']) + isset($_SESSION['user_id']) && + !$userHasReviewed ) { $rating = (int)$_POST['rating']; $comment = trim($_POST['comment']); @@ -392,7 +408,7 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0; mysqli_stmt_execute($stmtInsertRev); mysqli_stmt_close($stmtInsertRev); - // TRICK: JavaScript-Weiterleitung anstelle von PHP-Header! + // JS Weiterleitung echo ""; exit; } @@ -400,107 +416,49 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0; } ?> -
-

Füge deine Bewertung hinzu!

+
+ + - + - // 1. Prüfen, ob der eingeloggte Nutzer schon bewertet hat - if (isset($_SESSION['user_id'])) { - $stmtCheckRev = mysqli_prepare($conn, "SELECT 1 FROM reviews WHERE userID = ? AND productID = ? LIMIT 1"); - mysqli_stmt_bind_param($stmtCheckRev, "ii", $_SESSION['user_id'], $productId); - mysqli_stmt_execute($stmtCheckRev); - mysqli_stmt_store_result($stmtCheckRev); + +
+ - if (mysqli_stmt_num_rows($stmtCheckRev) > 0) { - $userHasReviewed = true; - } - mysqli_stmt_close($stmtCheckRev); - } +
+ + - // 2. Bewertung speichern (NUR wenn noch keine existiert!) - if ( - $_SERVER['REQUEST_METHOD'] === 'POST' && - isset($_POST['submit_review']) && - isset($_SESSION['user_id']) && - !$userHasReviewed - ) { - $rating = (int)$_POST['rating']; - $comment = trim($_POST['comment']); - $userID = $_SESSION['user_id']; + + - if ($rating >= 1 && $rating <= 5 && !empty($comment)) { + + - $stmtInsertRev = mysqli_prepare( - $conn, - "INSERT INTO reviews (userID, productID, rating, comment) VALUES (?, ?, ?, ?)" - ); + + - if ($stmtInsertRev) { - mysqli_stmt_bind_param( - $stmtInsertRev, - "iiis", - $userID, - $productId, - $rating, - $comment - ); - - mysqli_stmt_execute($stmtInsertRev); - mysqli_stmt_close($stmtInsertRev); - - // JS Weiterleitung - echo ""; - exit; - } - } - } - ?> - -
- - - - + - - - - -
- - - - - - - - - - - - - - -
- - - - - - -
+ + +
+