1、今日完成任务:
(1)后端管理员管理模块的管理员列表显示以及添加、修改和删除操作。
(2)前端留言页面完成与后台数据库的绑定。
2、核心代码
<?php require_once '../function.php'; //显示所有数据 $sql="select * from admin;"; $rows=sel($sql); //数据的个数 $sqlNum="select count(*) from admin;"; $rowsNum=sel($sqlNum); ?> <div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont"></i> 批量删除</a> <a href="javascript:;" onclick="admin_add('添加管理员','admin-add.php','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont"></i> 添加管理员</a></span> <span class="r">共有数据:<strong><?php echo $rowsNum[0]['count(*)'];?></strong> 条</span> </div> <?php if($rows){?> <table class="table table-border table-bordered table-bg"> <thead> <tr> <th scope="col" colspan="9">员工列表</th> </tr> <tr class="text-c"> <th width="25"><input type="checkbox" name="" value=""></th> <th width="40">ID</th> <th width="150">登录名</th> <th width="90">手机</th> <th width="150">邮箱</th> <th>角色</th> <th width="130">加入时间</th> <th width="100">是否已启用</th> <th width="100">操作</th> </tr> </thead> <tbody> <?php foreach ($rows as $key=>$value){?> <tr class="text-c"> <td><input type="checkbox" value="1" name=""></td> <td><?php echo $rows[$key]['id']?></td> <td><?php echo $rows[$key]['adminName']?></td> <td><?php echo $rows[$key]['adminTel']?></td> <td><?php echo $rows[$key]['adminEmail']?></td> <td>超级管理员</td> <td><?php echo $rows[$key]['regTime']?></td> <td class="td-status"><span class="label label-success radius">已启用</span></td> <td class="td-manage"> <a title="编辑" href="javascript:;" onclick="admin_edit('管理员编辑','admin-add.php?id=<?php echo $rows[$key]["id"]?>','1','800','500')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a> <a title="删除" href="javascript:;" onclick="admin_del(this,'<?php echo $rows[$key]["id"]?>')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont"></i></a> </td> </tr> <?php }?> </tbody> </table> <?php }else{?> <p>暂无管理员信息</p> <?php }?>
<?php require_once '../function.php'; $Id=$_GET['id']; if(isset($Id)){ //echo "修改"; $sql="select * from admin where id='$Id';"; $rows=sel($sql); }else{ //echo "添加"; } ?> <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <meta name="renderer" content="webkit|ie-comp|ie-stand"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" /> <meta http-equiv="Cache-Control" content="no-siteapp" /> <!--[if lt IE 9]> <script type="text/javascript" src="lib/html5.js"></script> <script type="text/javascript" src="lib/respond.min.js"></script> <script type="text/javascript" src="lib/PIE_IE678.js"></script> <![endif]--> <link href="css/H-ui.min.css" rel="stylesheet" type="text/css" /> <link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" /> <link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" /> <link href="lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet" type="text/css" /> <!--[if IE 6]> <script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script> <script>DD_belatedPNG.fix('*');</script> <![endif]--> <title>添加管理员</title> </head> <body> <div class="pd-20"> <form action="admin-addAction.php?id=<?php echo $rows[0]['id']?>" method="post" class="form form-horizontal" id="form-admin-add"> <div class="row cl"> <label class="form-label col-3"><span class="c-red">*</span>管理员:</label> <div class="formControls col-5"> <input type="text" class="input-text" value="<?php echo $rows[0]['adminName']?>" placeholder="" id="user-name" name="user-name" datatype="*2-16" nullmsg="用户名不能为空"> </div> <div class="col-4"> </div> </div> <div class="row cl"> <label class="form-label col-3"><span class="c-red">*</span>初始密码:</label> <div class="formControls col-5"> <input type="password" placeholder="密码" autocomplete="off" value="<?php echo $rows[0]['adminPass']?>" class="input-text" datatype="*6-20" id="newpassword" name="newpassword" nullmsg="密码不能为空"> </div> <div class="col-4"></div> </div> <div class="row cl"> <label class="form-label col-3"><span class="c-red">*</span>确认密码:</label> <div class="formControls col-5"> <input type="password" placeholder="确认新密码" autocomplete="off" class="input-text Validform_error" errormsg="您两次输入的新密码不一致!" datatype="*" nullmsg="请再输入一次新密码!" id="newpassword2" name="newpassword2" value="<?php echo $rows[0]['adminPass']?>" > </div> <div class="col-4"> </div> </div> <div class="row cl"> <label class="form-label col-3"><span class="c-red">*</span>性别:</label> <div class="formControls col-5 skin-minimal"> <div class="radio-box"> <input type="radio" <?php if($rows[0]['adminSex']=="男"){echo "checked='checked'";} ?> id="sex-1" name="sex" value="男" datatype="*" nullmsg="请选择性别!"> <label for="sex-1">男</label> </div> <div class="radio-box"> <input type="radio" <?php if($rows[0]['adminSex']=="女"){echo "checked='checked'";} ?> id="sex-2" name="sex" value="女"> <label for="sex-2">女</label> </div> </div> <div class="col-4"> </div> </div> <div class="row cl"> <label class="form-label col-3"><span class="c-red">*</span>手机:</label> <div class="formControls col-5"> <input type="text" class="input-text" value="<?php echo $rows[0]['adminTel']?>" placeholder="" id="user-tel" name="user-tel" datatype="m" nullmsg="手机不能为空"> </div> <div class="col-4"> </div> </div> <div class="row cl"> <label class="form-label col-3"><span class="c-red">*</span>邮箱:</label> <div class="formControls col-5"> <input type="text" class="input-text" placeholder="@" name="email" id="email" datatype="e" nullmsg="请输入邮箱!" value="<?php echo $rows[0]['adminEmail']?>"> </div> <div class="col-4"> </div> </div> <div class="row cl"> <label class="form-label col-3">备注:</label> <div class="formControls col-5"> <textarea name="adminRemark" cols="" rows="" class="textarea" placeholder="说点什么...100个字符以内" dragonfly="true" onKeyUp="textarealength(this,100)"><?php echo $rows[0]['adminRemark']?></textarea> <p class="textarea-numberbar"><em class="textarea-length">0</em>/100</p> </div> <div class="col-4"></div> </div> <div class="row cl"> <div class="col-9 col-offset-3"> <input class="btn btn-primary radius" type="submit" value=" 提交 "> </div> </div> </form> </div> <script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> <script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script> <script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script> <script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script> <script type="text/javascript" src="js/H-ui.js"></script> <script type="text/javascript" src="js/H-ui.admin.js"></script> <script type="text/javascript"> $(function(){ $('.skin-minimal input').iCheck({ checkboxClass: 'icheckbox-blue', radioClass: 'iradio-blue', increaseArea: '20%' }); $("#form-admin-add").Validform({ tiptype:2, callback:function(form){ // form[0].submit(); // var index = parent.layer.getFrameIndex(window.name); // parent.$('.btn-refresh').click(); // parent.layer.close(index); } }); //验证两次密码输入是否一致 $("#newpassword2").blur(function(){ console.log($("#newpassword").val()); console.log($("#newpassword2").val()); console.log($("#newpassword").val()!=$("#newpassword2").val()); if($("#newpassword").val()!=$("#newpassword2").val()){ $(this).parents(".formControls").next().find(".Validform_checktip").remove(); $(this).parents(".formControls").next().append("<span class='Validform_checktip Validform_wrong' />"); $(this).parents(".formControls").next().find(".Validform_wrong").html("您两次输入的新密码不一致!"); return false; } }); }); </script> </body> </html>
admin-addAction.php
<?php require_once '../function.php'; $adminId=$_GET["id"]; $adminName=$_POST["user-name"]; $adminPwd1=$_POST["newpassword"]; $adminPwd2=$_POST["newpassword2"]; $adminSex=$_POST["sex"]; $adminSex=$_POST["sex"]; $adminTel=$_POST["user-tel"]; $adminTel=$_POST["user-tel"]; $adminEmail=$_POST["email"]; $adminRemark=$_POST["adminRemark"]; if($adminId!=0){ //修改 $sql="update admin set adminPass='$adminPwd1',adminName='$adminName',adminSex='$adminSex',adminTel='$adminTel',adminEmail='$adminEmail',adminRemark='$adminRemark' where id=$adminId;"; $result=oper($sql); }else{ //添加 $sql="insert into admin (adminPass,adminName,adminSex,adminTel,adminEmail,regTime) values('$adminPwd1','$adminName','$adminSex','$adminTel','$adminEmail',now());"; $result=oper($sql); } echo "<script>"; echo 'parent.location.href="admin-list.php";'; echo "parent.layer.closeAll();"; echo "</script>"; ?>
leftMessage.php
<?php session_start(); //需要判读一下有没有进行登录 如果有登录进行显示下面的页面 如果没有登录则进入登录界面 if(!isset($_SESSION["userAccount"])){ //存储一下当前url 用于登录成功之后跳回 $_SESSION["userUrl"]=$_SERVER['REQUEST_URI']; header("location:login.php"); die();//下面的代码不在执行 } ?> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>留言-客车网上售票系统</title> <link rel="stylesheet" type="text/css" href="css/base.css"/> <link rel="stylesheet" type="text/css" href="css/others.css"/> </head> <body> <!--头部--> <div class="header"> <div class="container clear"> <div class="left"><a href="index.html"><img src="img/logo_pc.png"/></a></div> <div class="right clear"> <ul class="nav left clear"> <li><a href="home.php">首页</a></li> <li><a href="ticketsOnline.html">在线订票</a></li> <li><a href="newsList.php">新闻公告</a></li> <li class="active"><a href="leftMessage.html">留言中心</a></li> <li><a href="userInfo.html">个人中心</a></li> </ul> <div class="right btns-links"> <?php if(isset($_SESSION["userAccount"])){?> <img class="h-avatar" src="img/avatar.jpg"/> <?php }else{ ?> <a href="login.php">登录</a> <a href="register.html">注册</a> <?php }?> </div> </div> </div> </div> <!--留言--> <div class="left-message-box"> <div class="container"> <form class="message-form" action="leftMessageAction.php" method="post"> <h3 class="color358EEC">用户留言</h3> <textarea name="leftMessage" class="leftMessage" rows="" cols=""></textarea> <p class="tips" style="text-align:center;color:red;display:none;">error</p> <input class="subbtn" type="submit" name="submit" id="submit" value="提交" /> </form> </div> </div> <!--优势--> <div class="register-advantage"> <div class="container"> <ul class="clear"> <li class="clear"> <div class="advantage-img left"><img src="img/icon_pinpaibaozheng.png"/></div> <div class="left"> <h4>品牌保证</h4> <p>提供正规的购票服务</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_kuaisufankui.png"/></div> <div class="left"> <h4>快速反馈</h4> <p>第一时间短信通知</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_fangbiankuaijie.png"/></div> <div class="left"> <h4>方便快捷</h4> <p>车站直接取票上车</p> </div> </li> <li class="clear"> <div class="advantage-img left"><img src="img/icon_zhifufangbian.png"/></div> <div class="left"> <h4>支付方便</h4> <p>支付宝微信</p> </div> </li> </ul> </div> </div> <script src="js/jquery-3.5.1.min.js" type="text/javascript" charset="utf-8"></script> <script> $(function(){ $("#submit").click(function(){ if($(".leftMessage").val().length<3){ $('.tips').show().html("留言至少输入3个字符"); return false; }else{ $('.tips').hide(); } }); }); </script> <!--底部--> <div class="register-footer"> <p>客车网上售票系统官方电话 400-100-1234 0371-1234567 客车网上售票信息公示</p> <p>客车网上售票系统 Copyright©2020-2030 版权所有 XXXXXX网络科技有限公司 豫ICP备15030935号-1</p> </div> </body> </html>
leftMessageAction.php
<?php session_start(); require_once 'function.php'; $leftMessage=$_POST["leftMessage"]; $userAccount=$_SESSION["userAccount"]; //获取用户id $sql="select * from UserInfo where userTel='$userAccount';"; $rows=sel($sql); $userId=$rows[0]["userId"]; //将留言添加至数据库 $sqlMsg="insert into LeftMessage (userId,content,leftTime) values($userId,'$leftMessage',NOW());"; $result=oper($sqlMsg); header("location:home.php;"); ?>