prepare("SELECT a.*, c.name cat_name, u.username FROM articles a LEFT JOIN categories c ON a.category_id=c.id JOIN users u ON a.user_id=u.id WHERE a.id=? AND a.status=?"); $stmt->execute([$id, "published"]); $article = $stmt->fetch(); if (!$article) { header("Location: " . SITE_URL . "index.php"); exit; } $pageTitle = $article["title"]; $pageName = ""; db()->prepare("UPDATE articles SET views=views+1 WHERE id=?")->execute([$id]); record_visit("article/" . $id); $tags = get_article_tags($id); $err = ""; $ok = ""; if ($_SERVER["REQUEST_METHOD"] === "POST" && isset($_POST["comment"])) { $author = trim($_POST["author"] ?? ""); $content = trim($_POST["content"] ?? ""); $parent = isset($_POST["parent_id"]) ? (int)$_POST["parent_id"] : 0; if ($author === "" || $content === "") { $err = "昵称和内容不能为空"; } else { $st = db()->prepare("INSERT INTO comments (article_id, parent_id, author, content, status) VALUES (?,?,?,?,'approved')"); $st->execute([$id, $parent ?: null, $author, $content]); $ok = "评论已提交"; } } $cmtStmt = db()->prepare("SELECT * FROM comments WHERE article_id=? AND status=? ORDER BY created_at ASC"); $cmtStmt->execute([$id, "approved"]); $comments = $cmtStmt->fetchAll(); require_once __DIR__ . "/includes/header.php"; ?>

次阅读 作者:
">

评论 ()

">

暂无评论