BBS项目(四)

帖子管理模块

后台:

分页搜索显示页

  1 <html>
  2 <head>
  3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  4 <title>帖子管理</title>
  5 <link href="../../public/admin/css/css.css" type="text/css" rel="stylesheet" />
  6 <link href="../../public/admin/css/main.css" type="text/css" rel="stylesheet" />
  7 <link rel="shortcut icon" href="../../public/admin/img/main/favicon.ico" />
  8 <style>
  9 body{overflow-x:hidden; background:#f2f0f5; padding:15px 0px 10px 5px;}
 10 #searchmain{ font-size:12px;}
 11 #search{ font-size:12px; background:#548fc9; margin:10px 10px 0 0; display:inline; 100%; color:#FFF; float:left}
 12 #search form span{height:40px; line-height:40px; padding:0 0px 0 10px; float:left;}
 13 #search form input.text-word{height:24px; line-height:24px; 180px; margin:8px 0 6px 0; padding:0 0px 0 10px; float:left; border:1px solid #FFF;}
 14 #search form input.text-but{height:24px; line-height:24px; 55px; background:url(../../public/admin/img/main/list_input.jpg) no-repeat left top; border:none; cursor:pointer; font-family:"Microsoft YaHei","Tahoma","Arial",'宋体'; color:#666; float:left; margin:8px 0 0 6px; display:inline;}
 15 #search a.add{ background:url(../../public/admin/img/main/add.jpg) no-repeat -3px 7px #548fc9; padding:0 10px 0 26px; height:40px; line-height:40px; font-size:14px; font-weight:bold; color:#FFF; float:right}
 16 #search a:hover.add{ text-decoration:underline; color:#d2e9ff;}
 17 #main-tab{ border:1px solid #eaeaea; background:#FFF; font-size:12px;}
 18 #main-tab th{ font-size:12px; background:url(../../public/admin/img/main/list_bg.jpg) repeat-x; height:32px; line-height:32px;}
 19 #main-tab td{ font-size:12px; line-height:40px;}
 20 #main-tab td a{ font-size:12px; color:#548fc9;}
 21 #main-tab td a:hover{color:#565656; text-decoration:underline;}
 22 .bordertop{ border-top:1px solid #ebebeb}
 23 .borderright{ border-right:1px solid #ebebeb}
 24 .borderbottom{ border-bottom:1px solid #ebebeb}
 25 .borderleft{ border-left:1px solid #ebebeb}
 26 .gray{ color:#dbdbdb;}
 27 td.fenye{ padding:10px 0 0 0; text-align:right;}
 28 .bggray{ background:#f9f9f9}
 29 </style>
 30 </head>
 31 <body>
 32 <!--main_top-->
 33 <table width="99%" border="0" cellspacing="0" cellpadding="0" id="searchmain">
 34   <tr>
 35     <td width="99%" align="left" valign="top">您的位置:帖子管理&nbsp;&nbsp;>&nbsp;&nbsp;帖子列表</td>
 36   </tr>
 37   <tr>
 38     <td align="left" valign="top">
 39     <table width="100%" border="0" cellspacing="0" cellpadding="0" id="search">
 40           <tr>
 41             <td width="90%" align="left" valign="middle">
 42              <form method="get" action="./postList.php">
 43              <span>帖子标题:</span>
 44              <input type="text" name="title" value="" class="text-word">
 45              <input name="" type="submit" value="查询" class="text-but">
 46              </form>
 47          </td>
 48            
 49           </tr>
 50     </table>
 51     </td>
 52   </tr>
 53   <tr>
 54     <td align="left" valign="top">
 55     
 56     <table width="100%" border="0" cellspacing="0" cellpadding="0" id="main-tab">
 57       <tr>
 58         <th align="center" valign="middle" class="borderright">编号</th>
 59         <th align="center" valign="middle" class="borderright">主题</th>
 60         <th align="center" valign="middle" class="borderright">发帖人</th>
 61         <th align="center" valign="middle" class="borderright">发帖时间</th>
 62         <th align="center" valign="middle" class="borderright">状态</th>
 63         <th align="center" valign="middle">操作</th>
 64       </tr>
 65       <?php
 66         
 67             //引入公共配置
 68             require("../../public/config.php");
 69             
 70             
 71             //1.链接数据库并判断
 72             $link=mysqli_connect(HOST,USER,PASS) or die("链接数据库失败!");
 73             
 74             //2.设置字符集
 75             mysqli_set_charset($link,CHARSET);
 76             
 77             //3.选择数据库
 78             mysqli_select_db($link,DBNAME);
 79             
 80             //=========================搜索代码==============================
 81             
 82             //定义一个存储搜索条件的变量
 83             $whereList = array();
 84             $urlList = array();    //用来维持条件的数组
 85             $whereList[]=" (recycle=0 || recycle=2)";
 86             //判断你有没有搜索姓名
 87             if(!empty($_GET['title'])){
 88                 $whereList[] = " title like '%{$_GET['title']}%'";
 89                 $urlList[] = "title={$_GET['title']}";
 90             }
 91             
 92             //定义一个存放where语句的变量
 93                 $where = "";
 94                 $url = "";    //存放url地址条件的变量
 95                 
 96             //拼装where语句
 97                 if(count($whereList)>0){
 98                     $where = " where ".implode("&&",$whereList);
 99                     $url = "&".implode("&",$urlList);
100                 }
101             //保证查询结果按id递增顺序显示
102             $where=$where;
103             
104         //===============================================================
105         
106             
107             
108         //===============分页代码========================================    
109             //判断分页
110             $page=isset($_GET['page'])?$_GET['page']:1;    //当前页
111             $pageSize=10;//页大小
112             $maxPage=0;    //总页数
113             $maxRows=0;    //数据总条数
114             
115             
116             
117             $sql="select * from post ".$where;
118             
119             $result=mysqli_query($link,$sql);
120             //得到数据总条数
121             $maxRows=mysqli_num_rows($result);
122             
123             //得到总页数
124             $maxPage=ceil($maxRows/$pageSize);
125             
126             if($page<1){
127                 $page=1;
128             }
129             
130             if($page>$maxPage){
131                 $page=$maxPage;
132             }
133         
134             $limit = " limit ".(($page-1)*$pageSize).",".$pageSize;
135             
136             
137         //============================================================================
138             
139             
140             //检索帖子
141             $sql="select * from post ".$where." order by top desc,elite desc,ctime desc".$limit;
142             
143             $result=mysqli_query($link,$sql);
144             
145             if($result && mysqli_num_rows($result)>0){
146                 
147                 while($rows=mysqli_fetch_assoc($result)){
148                     
149             
150         
151     
152       
153       ?>
154       
155       <tr onMouseOut="this.style.backgroundColor='#ffffff'" onMouseOver="this.style.backgroundColor='#edf5ff'">
156         <td align="center" valign="middle" class="borderright borderbottom"><?php echo $rows['id'] ?></td>
157         <td align="center" valign="middle" class="borderright borderbottom" width="200"><?php echo $rows['title'] ?></td>
158         <td align="center" valign="middle" class="borderright borderbottom" >
159         <?php 
160             //发帖人昵称
161                 $sql="select nickName from userdetail where uid={$rows['uid']}";
162                 $res=mysqli_query($link,$sql);
163                 
164                 $nickName=mysqli_fetch_assoc($res);
165                 echo $nickName['nickName'];
166         ?></td>
167         <td align="center" valign="middle" class="borderright borderbottom" width="200">
168         <?php
169             //发帖时间
170                 echo date("Y/m/d H:i:s",$rows['ctime']);
171             
172         ?></td>
173         <td align="center" valign="middle" class="borderright borderbottom" width="120">
174         <?php
175             //状态
176                 echo $rows['top']?"已置顶":"普通";
177                 echo "/";
178                 echo $rows['elite']?"已加精":"普通";        
179         ?></td>
180        
181         <td align="center" valign="middle" class="borderbottom" width="300"><a href="./doAction.php?id=<?php echo $rows['id']; ?>&action=elite" target="mainFrame" onFocus="this.blur()" class="add"><?php echo $rows['elite']?"取消精华":"加精"; ?></a><span class="gray">&nbsp;|&nbsp;</span><a href="./doAction.php?id=<?php echo $rows['id']; ?>&action=top" target="mainFrame" onFocus="this.blur()" class="add"><?php echo $rows['top']?"取消置顶":"置顶"; ?></a><span class="gray">&nbsp;|&nbsp;</span><a href="./doEdit.php?id=<?php echo $rows['id']; ?>" target="mainFrame" onFocus="this.blur()" class="add">编辑</a><span class="gray">&nbsp;|&nbsp;</span><a href="./reply.php?id=<?php echo $rows['id']; ?>" target="mainFrame" onFocus="this.blur()" class="add">管理回复</a><span class="gray">&nbsp;|&nbsp;</span><a href="./doAction.php?id=<?php echo $rows['id']; ?>&action=recycle" target="mainFrame" onFocus="this.blur()" class="add">回收站</a></td>
182       </tr>
183       <?php
184       
185                 }
186                 //释放资源
187                 mysqli_free_result($result);
188             }
189                 
190       
191       
192       ?>
193       
194 
195     </table></td>
196     </tr>
197   <tr>
198     <td align="left" valign="top" class="fenye"><?php echo $maxRows ?>条数据 <?php echo $page ?>/<?php echo $maxPage ?> 页&nbsp;&nbsp;<a href="postList.php?page=1<?php echo $url?>" target="mainFrame" onFocus="this.blur()">首页</a>&nbsp;&nbsp;<a href="postList.php?page=<?php echo ($page-1).$url ?>" target="mainFrame" onFocus="this.blur()">上一页</a>&nbsp;&nbsp;<a href="postList.php?page=<?php echo ($page+1).$url ?>" target="mainFrame" onFocus="this.blur()">下一页</a>&nbsp;&nbsp;<a href="postList.php?page=<?php echo $maxPage.$url ?>" target="mainFrame" onFocus="this.blur()">末页</a></td>
199   </tr>
200   <?php
201   
202         //关闭链接
203         
204         mysqli_close($link);
205   
206   ?>
207 </table>
208 </body>
209 </html>

 doAction.php

  1 <?php
  2 
  3     //引入公共配置
  4     require("../../public/config.php");
  5     
  6     //1.链接数据库并判断
  7     $link=mysqli_connect(HOST,USER,PASS) or die("链接数据库失败!");
  8     
  9     //2.设置字符集
 10     mysqli_set_charset($link,CHARSET);
 11     
 12     //3.选择数据库
 13     mysqli_select_db($link,DBNAME);
 14     
 15     switch($_GET['action']){
 16         
 17         //加精
 18         case "elite":
 19             
 20             //4.定义sql
 21             $sql="update post set elite=1 where id={$_GET['id']}";
 22             $result=mysqli_query($link,$sql);
 23             
 24             if($result && mysqli_affected_rows($link)>0){
 25                 echo "<script>alert('加精成功!');window.location.href='postList.php'</script>";
 26             }else{
 27                 $sql="update post set elite=0 where id={$_GET['id']}";
 28                 $result=mysqli_query($link,$sql);
 29                 
 30                 echo "<script>alert('已取消精华!');window.location.href='postList.php'</script>";
 31             }
 32         break;
 33         
 34         //置顶
 35         case "top":
 36             
 37             //4.定义sql
 38             $sql="update post set top=1 where id={$_GET['id']}";
 39             $result=mysqli_query($link,$sql);
 40             
 41             if($result && mysqli_affected_rows($link)>0){
 42                 echo "<script>alert('置顶成功!');window.location.href='postList.php'</script>";
 43             }else{
 44                 $sql="update post set top=0 where id={$_GET['id']}";
 45                 $result=mysqli_query($link,$sql);
 46                 
 47                 echo "<script>alert('已取消置顶!');window.location.href='postList.php'</script>";
 48             }
 49         break;
 50         
 51         //回收站
 52         case "recycle":
 53         
 54             $sql="update post set recycle=1 where id={$_GET['id']}";
 55             
 56             $result=mysqli_query($link,$sql);
 57             
 58             if($result && mysqli_affected_rows($link)>0){
 59                 echo "<script>alert('放入回收站!');window.location.href='postList.php'</script>";
 60             }else{
 61                 $sql="update post set recycle=0 where id={$_GET['id']}";
 62                 $result=mysqli_query($link,$sql);
 63                 echo "<script>alert('帖子已还原!');window.location.href='recycle.php'</script>";
 64             }
 65         break;
 66         
 67         //删除帖子
 68         case "delete":
 69             
 70             $sql="delete from post where id={$_GET['id']}";
 71             $result=mysqli_query($link,$sql);
 72             
 73             if($result && mysqli_affected_rows($link)>0){
 74                 echo "<script>alert('删除帖子成功!');window.location.href='recycle.php'</script>";
 75             }
 76         break;
 77         //删除帖子回复
 78         case "del":
 79             
 80             $sql="delete from reply where id={$_GET['id']}";
 81             $result=mysqli_query($link,$sql);
 82             
 83             if($result && mysqli_affected_rows($link)>0){
 84                 echo "<script>alert('删除回复成功!');window.location.href='reply.php?id={$_GET['fid']}'</script>";
 85             }
 86         break;
 87         
 88         case "update":
 89             
 90             $set=array();
 91             if($_POST['title']!=""){
 92                 $set[]="title='{$_POST['title']}'";
 93             }
 94             if($_POST['content']!=""){
 95                 $set[]="content='{$_POST['content']}'";
 96             }
 97             if($_POST['recycle']!=""){
 98                 $set[]="recycle='{$_POST['recycle']}'";
 99             }
100             
101             $set=" set ".implode(",",$set);
102             
103             $sql="update post {$set} where id={$_GET['id']}";
104             $result=mysqli_query($link,$sql);
105             
106             if($result && mysqli_affected_rows($link)>0){
107                 echo "<script>alert('修改成功!');window.location.href='doEdit.php?id={$_GET['id']}'</script>";
108             }else{
109                 echo "<script>alert('修改失败!');window.location.href='doEdit.php?id={$_GET['id']}'</script>";
110             }
111             
112             
113         break;
114         
115     }
116 
117     mysqli_close($link);
118 
119 ?>

前台

发帖mark.php

  1 <!doctype html>
  2 <html>
  3     <head>
  4         
  5         
  6         <link rel='stylesheet' type='text/css' href='../public/home/css/mark.css'/>
  7     
  8         <!--头部开始-->
  9         
 10         <?php 
 11             require("header.php"); 
 12         
 13     
 14             if(empty(@$_SESSION['id'])){
 15                 echo "<script>alert('请先登录后再发帖!');window.location.href='./login.php';</script>";
 16                 die();
 17             }
 18         ?>
 19         
 20     <div class='clear'></div>
 21     
 22     <!--主体开始-->
 23     <div id='content'>
 24         <div style="font-size:14px;"><pre><img src='../public/home/webpic/ydjian.png'><a href='./index.php'>LAMP兄弟连</a>&gt;<a href='./detail.php?id=<?php echo $_GET['tid'] ?>'><?php
 25 
 26             //1.链接数据库并判断
 27             $link=mysqli_connect(HOST,USER,PASS) or die("链接数据库失败!");
 28             
 29             //2.设置字符集
 30             mysqli_set_charset($link,CHARSET);
 31             
 32             //3.选择数据库
 33             mysqli_select_db($link,DBNAME);
 34             
 35             //根据GET中的tid获得板块的名称
 36                 $sql="select name from type where id={$_GET['tid']} ";
 37                 $res=mysqli_query($link,$sql);
 38                 
 39                 if($res && mysqli_num_rows($res)>0){
 40                     $name=mysqli_fetch_assoc($res);
 41                     echo $name['name'];
 42                     mysqli_free_result($res);
 43                 }
 44         
 45         ?></a>&gt;发帖子                                                 </pre>
 46         </div>
 47         <div id='contentMain'>
 48         
 49         <form action='./type/doAction.php?action=insert&id=<?php echo $_GET['tid'] ?>' method='post' >
 50             <div id='CM1'>
 51                 <pre><div class='CM11'>发表主题</div><div class='CM11'>发起投票</div>                                                                                                          <b>板块权限查看</b></pre>
 52             </div>
 53             <div id='CM2'>
 54                 <select name="recycle" style="height:30px;font-size:20px">
 55                     <option>允许回复</option>
 56                     <option value='2' >不许回复</option>
 57                     
 58                     
 59                 </select>
 60                 <input type='text' name='utitle' style="height:30px;font-size:20px" />
 61             </div>
 62             <div id="CM3">
 63                 批量上传文件需要先选择文件,再选择上传!
 64             </div>
 65             <div id='CM4'>
 66                 <img src='../public/home/webpic/a8.jpg'/>
 67                 <textarea rows='10' cols='115' name='utxt' style="948px; height:200px;" draggable='true'></textarea>
 68             </div>
 69             <div id='CM5'>
 70                 <div class='CM51'>□常用设置</div>
 71                 <div class='CM51'>□售密设置</div>
 72                 <div class='CM51'>□回帖奖励</div>
 73                 <div class='CM51'>□高级</div>
 74             </div>
 75             <div id='CM6'>
 76                 <div style='padding-top:20px;padding-left:20px;font-size:12px;'>
 77                     <pre><input type='checkbox' />回复站内短信提醒    <input type='checkbox' />匿名帖    <input type='checkbox' />使用HTML代码    <input type='checkbox' />隐藏此贴(回复可见)    </pre>
 78                 </div>
 79                 <div style='padding-top:20px;padding-left:20px;font-size:14px;'><img src='../public/home/webpic/ata.jpg'/>提到某人:<input type='text' style='background:url("../public/home/webpic/xiala.jpg") no-repeat right;300px;height:20px;'/><sub>可以@您关注的人,最多可@10人,提升等级可@更多的人</sub></div>
 80             </div>
 81             <div id='CM7'>
 82                 
 83                 <input type='submit' value='发布' style="height:30px;80px;background:#ed9300;margin-left:10px;margin-top:10px;"/>
 84                 <button style="height:30px;80px;background:#efefef;margin-left:10px;margin-top:10px;">预览</button>
 85                 <button style="height:30px;80px;background:#efefef;margin-left:10px;margin-top:10px;">存为草稿</button>
 86             </div>
 87             
 88         </form>    
 89         </div>
 90     </div>
 91     
 92     <!--主体结束-->
 93 
 94     <div class='clear'></div>
 95     <!--页脚开始-->
 96     <?php require("footer.php");?>
 97     <!--页脚结束-->
 98     
 99     </body>
100 </html>
  1 <?php
  2 // +----------------------------------------------------------------------
  3 // | All Rights Reserved, Copyright (C) 2016, Irving_yx LAMP149, XDL
  4 // +----------------------------------------------------------------------
  5     //打开session
  6     session_start();
  7     
  8     //引入公共配置
  9     require("../../public/config.php");
 10     
 11     //1.链接数据库并判断
 12     $link=mysqli_connect(HOST,USER,PASS) or die("链接数据库失败!");
 13     
 14     //2.设置字符集
 15     mysqli_set_charset($link,CHARSET);
 16     
 17     //3.选择数据库
 18     mysqli_select_db($link,DBNAME);
 19     
 20     
 21     switch($_GET['action']){
 22         
 23         //发帖
 24         case "insert":
 25             
 26             $uid=$_SESSION['id'];
 27             $tid=$_GET['id'];
 28             $title=$_POST['utitle'];
 29             $content=$_POST['utxt'];
 30             $ctime=time();
 31             
 32             //排除空帖情况
 33             if($title==""||$content==""){
 34                 echo "<script>alert('请填写正确的标题和内容!!');window.location.href='../mark.php?tid={$tid}';</script>";die;
 35             }
 36             
 37             if($_POST['recycle']==2){
 38                 $sql="insert post(uid,tid,title,content,ctime,recycle) values({$uid},{$tid},'{$title}','{$content}',{$ctime},2)";
 39             }else{
 40                 $sql="insert post(uid,tid,title,content,ctime) values({$uid},{$tid},'{$title}','{$content}',{$ctime})";
 41             }
 42             
 43             
 44             //4.定义sql语句发送并执行
 45             
 46             $result=mysqli_query($link,$sql);
 47             
 48             
 49             //5.判读是否插入成功
 50             if($result && mysqli_affected_rows($link)>0){
 51                     
 52                 $id=mysqli_insert_id($link);
 53                 echo "<script>alert('发表成功!+10分^_^');window.location.href='../detail.php?id={$id}';</script>";
 54                 
 55                 //发帖加分+100
 56                 $sql="update userdetail set fraction=fraction+10 where uid={$uid}";
 57                 mysqli_query($link,$sql);
 58             }
 59 
 60         break;
 61         
 62         case "reply":
 63             
 64             //回帖先判断登录状态
 65             if(!isset($_SESSION['id'])){
 66                 echo "<script>alert('请先登录!');window.location.href='../login.php';</script>";
 67                 die;
 68             }
 69             $pid=$_GET['pid'];
 70             //判断回复内容不能空
 71             if($_POST['utxt']==""){
 72                 
 73                 
 74                 echo "<script>alert('不能空回复!!');window.location.href='../detail.php?id={$pid}';</script>";
 75                 die;
 76             }
 77             
 78             
 79             
 80             //获取回复时间
 81             $time=time();
 82             //定义sql发送执行
 83             $sql="insert reply values(null,{$_SESSION['id']},{$pid},'{$_POST['utxt']}',{$time})";
 84             $result=mysqli_query($link,$sql);
 85             
 86             if($result && mysqli_affected_rows($link)>0 ){
 87                 
 88                 //回帖加分
 89                 $sql="update userdetail set fraction=fraction+5 where uid={$_SESSION['id']}";
 90                 mysqli_query($link,$sql);
 91                 
 92                 echo "<script>alert('回复成功!+5分^_^');window.location.href='../detail.php?id={$pid}';</script>";
 93                 die;
 94             }else{
 95                 echo "<script>alert('回复失败!');window.location.href='../detail.php?id={$pid}';</script>";
 96                 die;
 97             }
 98             
 99             
100             
101         break;
102         
103     }
104 
105     //6.关闭链接
106     mysqli_close($link);
107 
108 ?>
原文地址:https://www.cnblogs.com/yexiang520/p/5608726.html