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; - } - } - } - ?> - -
- - - - + - - - - -
- - - - - - - - - - - - - - -
- - - - - - -
+ + +
+