diff --git a/productpage.php b/productpage.php index 9f766f7..47a10a6 100644 --- a/productpage.php +++ b/productpage.php @@ -358,54 +358,79 @@ $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!

+ 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; + } + } + } + ?> +
- + + + + + + +
@@ -431,11 +456,6 @@ $productId = isset($_GET['id']) ? (int)$_GET['id'] : 0;
- -

Du musst eingeloggt sein, um eine Bewertung abzugeben.

- - -