<?php
require_once 'config.php';
header('Content-Type: application/json');

$post_id = (int)$_POST['post_id'];
$name = $conn->real_escape_string($_POST['name'] ?? '');
$email = $conn->real_escape_string($_POST['email'] ?? '');
$comment = $conn->real_escape_string($_POST['comment'] ?? '');

if($post_id && $name && $comment) {
    $conn->query("INSERT INTO blog_comments (post_id, name, email, comment, status, created_at) 
                  VALUES ($post_id, '$name', '$email', '$comment', 'pending', NOW())");
    echo json_encode(['success' => true]);
} else {
    echo json_encode(['success' => false]);
}
?>