代码拉取完成,页面将自动刷新
<meta charset="UTF-8">
<?php
require ('./lib/init.php');
$art_id = $_GET['art_id'];
$sql = "select cat_name,cat_id from cat";
$cats = mGetAll($sql);
//art_id 是否合法
if (!is_numeric($art_id)){
header('location:index.php');
}
//判断文章是否存在 没有就跳转到首页
$sql = "select * from art where art_id = $art_id";
if (!mGetRow($sql)){
header('location:index.php');
}
//查询文章
$sql = "select title,content,author,pubtime,cat_name,comm,pic from art inner join cat on art.cat_id = cat.cat_id where art_id = $art_id";
$art = mGetRow($sql);
//查询所有的留言
$sql = "select nick,pubtime,content from comment where art_id = $art_id";
$comms = mGetAll($sql);
// post 非空 代表有留言
if (!empty($_POST)){
$comm['nick'] = trim($_POST['nick']);
$comm['email'] = trim($_POST['email']);
$comm['content'] = htmlspecialchars(trim($_POST['content']));
$comm['pubtime'] = time();
$comm['art_id'] = $art_id;
$comm['ip'] = sprintf('%u',ip2long(getRealIp()));
if ($comm['nick'] =='' or $comm['content'] == '') error('昵称和内容不能为空!');
$rs = mExec('comment',$comm);
if ($rs){
//评论发布成功 对应文章的comm数量+1
$sql = "update art set comm = comm + 1 where art_id = $art_id";
mQuery($sql);
//跳转到上个页面
$ref = $_SERVER['HTTP_REFERER'];
header("location:$ref ");
}
}
require (ROOT . '/view/front/art.html');
?>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。