ez-api/includes/submit_comment.php
2024-10-29 13:13:37 +08:00

17 lines
766 B
PHP

<?php
if (isset($_SESSION['user_id']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
// 获取表单数据并清理
$content = htmlspecialchars($_POST['commentContent'], ENT_QUOTES, 'UTF-8');
$user_id = $_SESSION['user_id'];
if (isset($_POST['love_wall_id'])) {
$love_wall_id = intval($_POST['love_wall_id']);
$stmt = $pdo->prepare("INSERT INTO comments (user_id, content, love_wall_id) VALUES (?, ?, ?)");
$stmt->execute([$user_id, $content, $love_wall_id]);
} elseif (isset($_POST['article_id'])) {
$article_id = intval($_POST['article_id']);
$stmt = $pdo->prepare("INSERT INTO comments (user_id, content, article_id) VALUES (?, ?, ?)");
$stmt->execute([$user_id, $content, $article_id]);
}
}
?>