<?php
require_once "../db.php";
session_start();

if (!isset($_SESSION['user_id'])) {
    die("Not logged in");
}

$user_id = $_SESSION['user_id'];
$post_id = intval($_POST['post_id'] ?? 0);

if (!$post_id) die("Missing post ID");

$stmt = $pdo->prepare("
    INSERT IGNORE INTO ratings (post_id, user_id)
    VALUES (?, ?)
");
$stmt->execute([$post_id, $user_id]);

header("Location: ../post.php?id=" . $post_id);