This repository has been archived on 2024-12-27. You can view files and clone it, but cannot push or open issues or pull requests.
ez-site/apis/submit_love.php
2024-10-19 21:33:47 +08:00

20 lines
566 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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 "发表失败!";
}
}
?>