<?php
require 'config/db.php';

if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $order_id = (int)$_POST['order_id'];
    $seller_id = (int)$_POST['seller_id'];
    $rating = (int)$_POST['rating'];
    $comment = htmlspecialchars($_POST['comment']);

    $stmt = $pdo->prepare("INSERT INTO reviews (order_id, seller_id, buyer_id, rating, comment) VALUES (?, ?, ?, ?, ?)");
    $stmt->execute([$order_id, $seller_id, $_SESSION['user_id'], $rating, $comment]);

    header("Location: my_orders.php?status=reviewed");
}