ez-api/includes/submit_love.php

20 lines
566 B
PHP
Raw Normal View History

2024-10-29 13:13:37 +08:00
<?php
// 检查session中的user_id是否存在并且请求方法是POST
if (isset($_SESSION['user_id']) && $_SERVER['REQUEST_METHOD'] == 'POST') {
// 获取表单数据并清理
$content = htmlspecialchars($_POST['content'], ENT_QUOTES, 'UTF-8');
$user_id = $_SESSION['user_id'];
// 准备SQL语句
$stmt = $pdo->prepare("INSERT INTO love_wall (user_id, content) VALUES (?, ?)");
// 执行SQL语句
if ($stmt->execute([$user_id, $content])) {
echo "发表成功!";
} else {
echo "发表失败!";
}
}
?>