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

<?php
date_default_timezone_set('Asia/Kolkata');
include "db.php";

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = mysqli_real_escape_string($conn, $_POST['name']);
    $content = mysqli_real_escape_string($conn, $_POST['content']);
    $created_at = date("Y-m-d H:i:s");

    $sql = "INSERT INTO reviews (name, content, created_at) VALUES ('$name', '$content', '$created_at')";

    if (mysqli_query($conn, $sql)) {
        
        echo '
        <script>
        Swal.fire({
            icon: "success",
            title: "Review Submitted",
            text: "Thank you for your feedback!",
            confirmButtonColor: "#28a745"
        }).then(() => {
            window.location.href = "review.php";
        });
        </script>';
    } else {
       
        echo '
        <script>
        Swal.fire({
            icon: "error",
            title: "Failed",
            text: "Could not submit your review. Try again later."
        }).then(() => {
            window.history.back();
        });
        </script>';
    }
}
?>

</body>
</html>