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;
}
}
}
?>
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;
}
}
}
?>
Du hast dieses Produkt bereits bewertet. Vielen Dank!