From 9a3cdd975a042a86a0e00dd9b11253779a63bc10 Mon Sep 17 00:00:00 2001 From: fsst Date: Wed, 18 Mar 2026 15:39:15 +0100 Subject: [PATCH] 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; + } + } + } + ?> + +
+ + - + + - - - - - + +
+ + +
+ + + + + + + + + + + + + + +
+ + + + +
+ +
-