zoukankan      html  css  js  c++  java
  • 后端模块-管理员登录、显示留言列表

    1、今日完成任务:

    (1)管理员登录

    (2)显示留言列表

    2、核心代码

    数据库:

    -- 创建数据库   BusSystem
    drop database if exists BusSystem;
    create database BusSystem;
    use BusSystem;
    -- 创建用户表
    drop table if exists UserInfo;
    create table UserInfo(
    userId int not null PRIMARY key auto_increment,
    userTel char(11) not null,
    userPass char(8) not null,
    nickname varchar(10),
    regTime datetime
    );
    -- 留言表
    drop table if exists LeftMessage;
    create table LeftMessage(
    id int not null PRIMARY key auto_increment,
    userId int not null references UserInfo(userId),
    content varchar(200),
    leftTime datetime
    );
    -- 管理员表
    drop table if exists admin;
    create table admin(
    id int not null PRIMARY key auto_increment,
    adminNo int not null,-- 工号
    adminPass varchar(8) not null,
    adminName varchar(8)
    );
    -- 添加输入
    insert into admin (adminNo,adminPass,adminName) values(001,'123456','admin');
    insert into admin (adminNo,adminPass,adminName) values(002,'123456','root');
    select * from admin where adminName="admin" and adminPass="123456";
    select * from admin where adminName="root" and adminPass="123456";
    
    --  添加用户
    select * from UserInfo;
    insert into UserInfo (userTel,userPass,nickname) values('13678909876','123456','nick');
    --  添加留言
    select * from LeftMessage , userinfo where leftmessage.userId=userinfo.userId;
    insert into LeftMessage (userId,content,leftTime) values(1,"写什么呢",NOW());

    后台代码:

    <?php
    //开启session
    session_start();
    //引入数据库操作方法文件
    require_once '../function.php';
    //用户登录
    if(isset($_POST["username"])){
        $username=$_POST["username"];
        $pwd=$_POST["pwd"];
        $sql="select * from admin where adminName='$username' and adminPass='$pwd';";
        $rows=sel($sql);
        if($rows){
            //echo "登录成功";
            //把登录信息存储到session
            $_SESSION["username"]=$username;
            $_SESSION["pwd"]=$pwd;
            $autoValue=$_POST["online"];
            
            //保存登录  默认保存7天
            if($autoValue=="yes"){
                setcookie("auto",1,time()+60*60*24*7);//存储7天
            }
            header("location:index.php");
        }else{
            //echo "登录失败";
            header("location:login.html");
        }
    }
    
    
    
    
    ?>
    <?php foreach ($rows as $key=>$value){ ?>
                    <tr class="text-c">
                        <td><input type="checkbox" value="1" name=""></td>
                        <td><?php echo $rows[$key]["userId"] ?></td>
                        <td><a href="javascript:;"><i class="avatar size-L radius" style="line-height:40px;"><?php echo $rows[$key]["nickname"] ?></i></a></td>
                        <td class="text-l">
                            <div class="f-12 c-999"><?php echo $rows[$key]["content"] ?></div>
                            <div class="c-999 f-12">
                                <time datetime="<?php echo $rows[$key]["leftTime"] ?>"><?php echo $rows[$key]["leftTime"] ?></time>
                            </div>
                        </td>
                        <td class="td-manage"><a title="编辑" href="javascript:;" onclick="member_edit('编辑','member-add.html','4','','510')" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a> <a title="删除" href="javascript:;" onclick="member_del(this,'1')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a></td>
                    </tr>
                <?php }?>
  • 相关阅读:
    为结构体中函数指针赋值的两种方法(转)
    (obj) error: LNK2019: 无法解析的外部符号解决方法
    js cookie存储方法
    js关于对象键值为数字型时输出的对象自动排序问题的解决方法
    HTML5 LocalStorage 本地存储的用法
    onhashchange事件,只需要修改hash值即可响应onhashchange事件中的函数(适用于上一题下一题和跳转页面等功能)
    js实现页面a向页面b传参的方法
    前端比较好的学习资料(包括js和css)以及 最全前端资源汇集
    字符串js编码转换成实体html编码的方法(防范XSS攻击)
    fis3使用环境
  • 原文地址:https://www.cnblogs.com/jn003/p/13331419.html
Copyright © 2011-2022 走看看