ez-site/apis/submit_comment.php

17 lines
766 B
PHP
Raw Normal View History

2024-10-19 21:33:47 +08:00
<?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]);
}
}
?>