为了维护和管理留言本,针对留言本设置来一个管理员,该管理员在前台进行擦做,称为版主.
需要在MYSQL数据库中,手动添加一个系统版主的数据,当版主相对留言本进行管理时,点击首页"版主管理",登录即可.
下面代码为验证是否为版主进行登录
<?php
session_start();
include("conn/conn.php");
if(isset($_SESSION['unc'])){
echo "<script>alert('在同一台机器上,不允许同事使用用户名和管理员进行登录!');window.location.hred='index.php';</script>";
}else{
if(isset($_POST['Submit']) && $_POST['Submit'] == "登录"){
if($_POST['username'] != "" && S_POST['[password']) !=""){
$check="select userword from tb_adm where userword='".$_POST['username']."'and password='".$_POST['password']."'";
$result=mysql_query($check,$conn);
$info=mysql_num_rows($result);
if($info==1){
$_SESSION["userword"]=$_POST['username'];
echo "<scirpt>alert('登录成功');window.location.href='admin_browse.php';</script>";
}else{
echo "<script>alert('登录失败,不是版主账号');window.location.href='index.php';</script>"
}
}
}
}
?>
版本登录进去后,可以对主题进行删除操作
删除操作代码如下:
<?php
session_start(); //启用session支持
include_once("conn/conn.php");
if(isset($_SESSION['userword']) && isset($_GET["del_id"])){
//通过传递的ID值,删除留言表中的留言
$result=mysql_query("delete from tb_leaveword where id='".$_GET["del_id"]."'",$conn);
//查询回复表中对该主题的回复
$res=mysql_query("select * from tb_replyword where leave_id='".$_GET["del_id"]."'",$conn);
if(mysql_num_rows($res)>0){
//当回复表中的记录数大于0时,查询回复表中对该主题的回复
$result=mysql_query("delete from tb_replyword where leave_id='".$_GET["del_id"]."'",$conn);
//当主题和回复都存在时,执行全主题删除
if($result==true and $result==true){
echo "<script>alert('留言删除成功!');history.back();</script>";
}else{
echo "<scirpt>alert('留言删除失败!');histroy.back();</script>";
}
}else{
if($result){
echo "<script>alert('留言删除成功!');histroy.back();</script>";
}else{
echo "<scirpt>alert('您没有删除权限!');history.back();</scirpt>";
}
}else{
echo "<scirpt>alert('您没有删除权限!');history.back();</script>";
}
?>