20 lines
566 B
PHP
20 lines
566 B
PHP
|
<?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 "发表失败!";
|
|||
|
}
|
|||
|
}
|
|||
|
?>
|