<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Update Review</title>
    <script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
</head>
<body>

<?php
include "db.php";

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $id = intval($_POST['edit_id']);
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $content = mysqli_real_escape_string($conn, $_POST['content']);

    $sql = "UPDATE reviews SET name='$name', content='$content' WHERE id=$id";

    if (mysqli_query($conn, $sql)) {
        echo '
        <script>
        Swal.fire({
            icon: "success",
            title: "Updated!",
            text: "Review has been updated successfully."
        }).then(() => {
            window.location.href = "review.php"; 
        });
        </script>';
    } else {
        echo '
        <script>
        Swal.fire({
            icon: "error",
            title: "Failed",
            text: "Error updating review."
        }).then(() => {
            window.history.back();
        });
        </script>';
    }
}
?>

</body>
</html>