首页 > 作文

电子商城项目开发(后台功能模块开发)

更新时间:2023-04-08 02:52:49 阅读: 评论:0

后台登陆页login.php

    <?php    //1.连接数据库 (创建一个数据库,创建数据表 test_admin)    //id, adminur, adminpass, created_at, login_at, login_ip    require '../db.func.php';    require '../tools.func.php';    // post提交    if (!empty($_post['adminur'])) {      //2.查询用户名和密码是否正确 adminur adminpass        $prefix = getdbprefix();        $adminur = htmlentities($_post['adminur']);        $adminpass = md5(htmlentities($_post['adminpass']));        $sql = "lect id, adminur from {$prefix}admin                         where adminur = '$adminur'                         and adminpass = '$adminpass'";        $res = queryone($sql);        if ($res) {        //3.写入ssion            tssion('admin',                ['adminur' => $adminur, 'id' => $res['id']]            );            $login_at = date('y-m-d h:i:s');            $ip = $_rver['remote_addr'] == '::1' ? '127.0.0.1' : $_rver['remote_addr'];            $login_ip = ip2long($ip);            $sql = "update {$prefix}admin                             t login_at = '$login_at', login_ip = '$login_ip'                             where id = '{$res['id']}'";            execute($sql);        //4.跳转到index.php            header('location: index.php');        } el {            tinfo('用户名或者密码错误');        }    }    ?>    <!doctype html>    <html>    <head>      <title>商城</title>      <!-- required meta tags -->      <meta chart="utf-8">      <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, ur-scalable=0" name="viewport" />      <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1" />      <!--     fonts and icons     -->      <link rel="stylesheet" type="text/css" href="asts/css/googlefonts.css?family=roboto:300,400,500,700|roboto+slab:400,700|material+icons" />      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">      <!-- material kit css -->      <link href="asts/css/material-dashboard.css?v=2.1.1" rel="stylesheet" />    </head>    <body>      <div class="wrapper ">        <div>          <div>            <div class="container" style="width: 50%;margin-top: 250px;">              <div class="row">                <div class="col-md-12">                  <div class="col-md-12">                    <div class="card">                      <div class="card-header card-header-primary">                        <h4 class="card-title">登录</h4>                        <p class="card-category">以管理员身份登录后台</p>                      </div>                      <div class="card-body">                          <p><?php if (hasinfo()) echo getinfo(); ?></p>                        <form action="login.php" method="post">                          <div class="row">                            <div class="col-md-12">                              <div class="form-group">                                <label class="bmd-label-floating">用户名</label>                                <input type="text" name="adminur" class="form-control">                              </div>                            </div>                          </div>                          <div class="row">                            <div class="col-md-12">                              <div class="form-group">                                <label class="bmd-label-floating">密码</label>                                <input type="password" name="adminpass" class="form-control">                              </div>                            </div>                          </div>                          <button type="submit" class="btn btn-primary pull-right">登录</button>                          <div class="clearfix"></div>                        </form>                      </div>                    </div>                  </div>                </div>              </div>            </div>          </div>        </div>      </div>      <script src="asts/js/core/jquery.min.js"></script>      <script src="asts/js/core/popper.min.js"></script>      <script src="asts/js/core/bootstrap-material-design.min.js"></script>    </body>    </html>

数据库结构shop.sql

    /*     navicat premium data transfer     source rver         : 127.0.0.1     source rver type    : mysql     source rver version : 80012     source host           : localhost:3306     source schema         : shop     target rver type    : mysql     target rver version : 80012     file encoding         : 65001     date: 26/01/2019 10:13:57    */    t names utf8mb4;    t foreign_key_checks = 0;    -- ----------------------------    -- table structure for test_admin    -- ----------------------------    drop table if exists `test_admin`;    create table `test_admin` (      `id` int(10) unsigned not null auto_increment,      `adminur` varchar(50) not null default '',      `adminpass` char(32) not null default '',      `created_at` varchar(255) not null default '',      `login_at` varchar(255) not null default '' ,      `login_ip` bigint(20) not null default '0',      primary key (`id`)    ) engine=innodb auto_increment=2 default chart=utf8;    -- ----------------------------    -- records of test_admin    -- ----------------------------    begin;    inrt into `test_admin` values (1, 'admin', '0192023a7bbd73250516f069df18b500', '2019-01-23 20:21:03', '2019-01-24 12:56:48', 2130706433);    commit;    -- ----------------------------    -- table structure for test_cart    -- ----------------------------    drop table if exists `test_cart`;    create table `test_cart` (      `id` int(10) unsigned not null auto_increment,      `price` decimal(10,2) unsigned not null default '0.00',      `quantity` int(10) unsigned not null default '0',      `products` text,      `uid` int(10) unsigned not null default '0',      `created_at` varchar(255) not null default '' ,      primary key (`id`)    ) engine=innodb auto_increment=3 default chart=utf8;    -- ----------------------------    -- records of test_cart    -- ----------------------------    begin;    inrt into `test_cart` values (2, 21700.00, 3, '{\"3\":{\"quantity\":2,\"product\":{\"id\":\"3\",\"name\":\"macbook pro\",\"price\":\"8800.00\",\"code\":\"88888888\",\"description\":\"macbook pro\"}},\"4\":{\"quantity\":1,\"product\":{\"id\":\"4\",\"name\":\"\\u534e\\u4e3a\\u624b\\u673a\",\"price\":\"4100.00\",\"code\":\"929868123123123\",\"description\":\"\\u5546\\u54c1\\u63cf\\u8ff0\\uff1a\\r\\n\\r\\n\\u8fd9\\u662f\\u534e\\u4e3a\\u624b\\u673a\"}}}', 5, '2019-01-24 10:53:24');    commit;    -- ----------------------------    -- table structure for test_order    -- ----------------------------    drop table if exists `test_order`;    create table `test_order` (      `id` int(10) unsigned not null auto_increment,    小记者自我介绍  `price` decimal(10,2) unsigned not null default '0.00',      `quantity` int(10) unsigned not null default '0',      `products` text,      `uid` int(10) unsigned not null default '0',      `created_at` varchar(255) not null default '' ,      primary key (`id`)    ) engine=innodb auto_increment=2 default chart=utf8;    -- ----------------------------    -- records of test_order    -- ----------------------------    begin;    inrt into `test_order` values (1, 17600.00, 2, '{\"3\":{\"quantity\":2,\"product\":{\"id\":\"3\",\"name\":\"macbook pro\",\"price\":\"8800.00\",\"code\":\"88888888\",\"description\":\"macbook pro\"}}}', 5, '2019-01-24 12:46:33');    commit;    -- ----------------------------    -- table structure for test_product    -- ----------------------------    drop table if exists `test_product`;    create table `test_product` (      `id` int(10) unsigned not null auto_increment,      `name` varchar(200) not null default '',      `code` varchar(100) not null default '',      `description` text,      `stock` int(10) unsigned not null default '0',      `price` decimal(10,2) unsigned not null default '0.00',     `created_at` varchar(255) not null default '' ,      primary key (`id`)    ) engine=innodb auto_increment=5 default chart=utf8;    -- ----------------------------    -- records of test_product    -- ----------------------------    begin;    inrt into `test_product` values (3, 'macbook pro', '88888888', 'macbook pro', 99, 8800.00, '2019-01-24 00:19:28');    inrt into `test_product` values (4, '华为手机', '929868123123123', '商品描述:\r\n\r\n这是华为手机', 99, 4100.00, '2019-01-24 00:31:28');    commit;    -- ----------------------------    -- table structure for test_ur    -- ----------------------------    drop table if exists `test_ur`;    create table `test_ur` (      `id` int(10) unsigned not null auto_increment,      `urname` varchar(100) not null default '',      `password` char(32) not null default '',      `name` varchar(100) not null default '',      `age` tinyint(3) unsigned not null default '0',      `email` varchar(100) not null default '',      `phone` varchar(20) not null default '',     `created_at` varchar(255) not null default '' ,      primary key (`id`)    ) engine=innodb auto_increment=6 default chart=utf8;    -- ----------------------------    -- records of test_ur    -- ----------------------------    begin;    inrt into `test_ur` values (3, 'zhangsan', '4297f44b13955235245b2497399d7a93', '张三', 28, '965794175@qq.com', '13200000000', '2019-01-23 23:54:34');    inrt into `test_ur` values (4, 'wangwu', '4297f44b13955235245b2497399d7a93', '', 0, 'wangwu@test.com', '', '2019-01-24 09:21:45');    inrt into `test_ur` values (5, 'zhaoliu', '4297f44b13955235245b2497399d7a93', '', 0, 'zhaoliu@test.com', '', '2019-01-24 09:35:05');    commit;    t foreign_key_checks = 1;

配置数据库文件config.php

    <?php    /**     * created by phpstorm.     * date: 2019/1/23     * time: 20:22     */    date_default_timezone_t('prc');    return [        'db_host' => '127.0.0.1',        'db_port' => '3306',        'db_ur' => 'root',        'db_pass' => '123456',        'db_name' => 'test_shop',        'db_prefix' => 'test_',        'db_chart' => 'utf8',    ];

操作数据库函数db.func.php

    <?php    function connect()    {        $config = require dirname(__file__) . '/config.php';        $mysqli = @mysqli_connect(            $config['db_host'] . ':' . $config['db_port'],            $config['db_ur'],            $config['db_pass'],            $config['db_name']        ) or die('connect error: ' . mysqli_connect_errno() . '-' . mysqli_connect_error());        mysqli_t_chart($mysqli, $config['db_chart']);        return $mysqli;    }    function queryone($sql)    {        $mysqli = connect();        $result = mysqli_query($mysqli, $sql);        $data = [];        if ($result && mysqli_num_rows($result) > 0) {            $data = mysqli_fetch_assoc($result);        }        return $data;    }    function query($sql)    {        $mysqli = connect();        $result = mysqli_query($mysqli, $sql);        $data = [];        if ($result && mysqli_num_rows($result) > 0) {            while ($res = mysqli_fetch_assoc($result)) {                $data[] = $res;            }        }        return $data;    }    function getdbprefix()    {        $config = require dirname(__file__) . '/config.php';        return $config['db_prefix'];    }    function execute($sql)    {        $mysqli = connect();        mysqli_query($mysqli, $sql);        return mysqli_affected_rows($mysqli) > 0;    }

公共函数文件tools.func.php

    <?php    /**     * created by phpstorm.     * date: 2019/1/23     * time: 20:31     */    function tssion($key, $data, $prefix = '')    {        ssion_id() || @ssion_start();        if (!empty($prefix)) {            $_ssion[$prefix][$key] = $data;        } el {            $_ssion[$key] = $data;        }    }    function getssion($key, $prefix = '')    {        ssion_id() || @ssion_start();        if (!empty($prefix)) {            return ist($_ssion[$prefix][$key]) ? $_ssion[$prefix][$key] : [];        } el {            return ist($_ssion[$key]) ? $_ssion[$key] : [];        }    }    function deletession($key, $prefix = '')    {        ssion_id() || @ssion_start();        if (!empty($prefix)) {            $_ssion[$prefix][$key] = null;        } el {            $_ssion[$key] = null;        }    }    function tinfo($info)    {        tssion('info', $info, 'system');    }    function getinfo()    {       $info = getssion('info', 'system');       deletession('info', 'system');       return $info;    }    function hasinfo()    {       return !empty(getssion('info', 'system'));    }

判断是否有登陆权限auth.php

    <?php    /**     * created by phpstorm.     * date: 2019/1/23     * time: 22:07     */    if (empty(getssion('adminur', 'admin'))) {        header('location: login.php');        exit;    }

登陆成功后进入后台首页index.php

    <?php    require '../db.func.php';    require '../tools.func.php';    require 'auth.php';    //1.查询数据库 test_admin    //2.写sql语句    $prefix = getdbprefix();    $sql = "lect id,adminur,created_at,login_at,login_ip                     from {$prefix}admin order by created_at desc";    $data = query($sql);    //3.遍历数据    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <h4 class="card-title ">所有管理员</h4>                    <p class="card-category"> 控制台所有管理员列表</p>                </div>                <div class="card-body">                    <div class="table-responsive">                        <table class="table table-hover">                            <thead class=" text-primary">                            <th>                                id                            </th>                            <th>                                用户名                            </th>                            <th>                                创建时间                            </th>                            <th>                                最后登录时间                            </th>                            <th>                                最后登录ip                            </th>                            </thead>                            <tbody>                            <?php foreach ($data as $admin): ?>                            <tr>                                <td>                                    <?php echo $admin['id']; ?>                                </td>                                <td>                    <?php echo $admin['adminur']; ?>                                </td>                                <td>                    <?php echo $admin['created_at']; ?>                                </td>                                <td>                    <?php echo $admin['login_at']; ?>                                </td>                                <td>                    <?php echo long2ip($admin['login_ip']); ?>                                </td>                            </tr>                            <?php endforeach; ?>                            </tbody>                        </table>                    </div>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

header.php

    <?php    $script = baname($_rver['script_filename']);    // 控制台 index.php admin_edit.php    // 用户管理 urs.php ur_add.php ur_edit.php    // 商品管理 products.php product_add.php product_edit.php    ?>    <!doctype html>    <html>    <head>        <title>商城</title>        <!-- required meta tags -->        <meta chart="utf-8">        <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, ur-scalable=0" name="viewport"/>        <meta http-equiv="x-ua-compatible" content="ie=edge,chrome=1"/>        <!--     fonts and icons     -->        <link rel="stylesheet" type="text/css"              href="asts/css/googlefonts.css?family=roboto:300,400,500,700|roboto+slab:400,700|material+icons"/>        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/latest/css/font-awesome.min.css">        <!-- material kit css -->        <link href="asts/css/material-dashboard.css?v=2.1.1" rel="stylesheet"/>    </head>    <body>    <div class="wrapper ">        <div class="sidebar" data-color="purple" data-background-color="white">            <div class="logo">                <a href="index.php" class="simple-text logo-normal">                    商城                </a>            </div>            <div class="sidebar-wrapper">                <ul class="nav">                    <li class="nav-item <?php echo substr($script, 0, 5) == 'index' || substr($script, 0, 5) == 'admin' ? 'active' : ''; ?>">                        <a class="nav-link" href="index.php">                            <i class="material-icons">dashboard</i>                            <p>控制台</p>                        </a>                    </li>                    <li class="nav-item <?php echo substr($script, 0, 4) == 'ur' ? 'active' : ''; ?>">                        <a class="nav-link" href="urs.php">                            <i class="material-icons">person</i>                            <p>用户管理</p>                        </a>                    </li>                    <li class="nav-item <?php echo substr($script, 0, 7) == 'product' ? 'active' : ''; ?>">                        <a class="nav-link" href="products.php">                            <i class="material-icons">library_books</i>                            <p>商品管理</p>                        </a>                    </li>                    <li class="nav-item <?php echo substr($script, 0, 4) == 'cart' ? 'active' : ''; ?>">                        <a class="nav-link" href="carts.php">                            <i class="material-icons">shopping_cart</i>                            <p>购物车管理</p>                        </a>                    </li>                    <li class="nav-item <?php echo substr($script, 0, 5) == 'order' ? 'active' : ''; ?>">                        <a class="nav-link" href="orders.php">                            <i class="material-icons">list</i>                            <p>订单管理</p>                        </a>                    </li>                    <!-- your sidebar here -->                </ul>            </div>        </div>        <div class="main-panel">            <!-- navbar -->            <nav class="navbar navbar-expand-lg navbar-transparent navbar-absolute fixed-top ">                <div class="container-fluid">                    <div class="navbar-wrapper">                        <a class="navbar-brand" href="index.php">控制台</a>                    </div>                    <div class="collap navbar-collap justify-content-end">                        <ul class="navbar-nav">                            <li class="nav-item dropdown">                                <a class="nav-link" href="#" id="navbardropdownprofile" data-toggle="dropdown" aria-haspopup="true"                                   aria-expanded="fal">                                    <i class="material-icons">person</i>                                    <p class="d-lg-none d-md-block">                                        管理员                                    </p>                                </a>                                <div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbardropdownprofile">                                    <a class="dropdown-item" href="admin_edit.php">编辑</a>                                    <div class="dropdown-divider"></div>                                    <a class="dropdown-item" href="logout.php">退出</a>                                </div>                            </li>                            <!-- your navbar here -->                        </ul>                    </div>                </div>            </nav>            <!-- end navbar -->            <div class="content">                <div class="container-fluid">

footer.php

    </div>    </div>    </div>    </div>    <script src="asts/js/core/jquery.min.js"></script>    <script src="asts/js/core/popper.min.js"></script>    <script src="asts/js/core/bootstrap-material-design.min.js"></script>    </body>    </html>

管理员账号密码修改admin_edit.php

    <?php    require '../tools.func.php';    require 'auth.php';    require '../db.func.php';    $current_ur = getssion('admin');    //1.判断是否为post提交    if (!empty($_post['adminpass'])) {      //2.验证新密码和确认密码是否一致        $adminpass = md5(htmlentities($_post['adminpass']));        $newpass = htmlentities($_post['newpass']);        $confirmpass = htmlentities($_post['confirmpass']);        if ($newpass != $confirmpass) {            tinfo('两次密码输入不一致');        } el {        //3.验证旧密码是否正确 (查询数据库 用id,adminpass)        $prefix = getdbprefix();        $sql = "lect id from {$prefix}admin                     where id = '{$current_ur['id']}'                     and adminpass = '$adminpass'                    ";        $res = queryone($sql);        //4.更新数据表 imooc_admin adminpass        if ($res) {          $pass = md5($newpass);          $sql = "update {$prefix}admin                     t adminpass = '$pass'                    where id = '{$current_ur['id']}'";          if (execute($sql)) {              tinfo('修改密码成功');          } el {              tinfo('修改密码失败');          }        } el {            tinfo('旧密码不正确!');        }        }        //5.显示结果到页面    }    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">         灭绝动物   <div class="card">                <div class="card-header card-header-primary">                    <h4 class="card-title">修改密码</h4>                    <p class="card-category">修改当前管理员密码</p>                </div>                <div class="card-body">                    <?php if (hasinfo()) echo getinfo(); ?>                    <form action="admin_edit.php" method="post">                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">用户名</label>                                    <input type="text" disabled name="adminur" value="<?php echo $current_ur['adminur']; ?>" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">旧密码</label>                                    <input type="password" name="adminpass" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">新密码</label>                                    <input type="password" name="newpass" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">确认密码</label>                                    <input type="password" name="confirmpass" class="form-control">                                </div>                            </div>                        </div>                        <button type="submit" class="btn btn-primary pull-right">修改</button>                        <div class="clearfix"></div>                    </form>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

管理员后台登出logout.php

    <?php    /**     * created by phpstorm.     * date: 2019/1/23     * time: 22:06     */    // 1. 删除当前登录用户的ssion    require '../tools.func.php';    deletession('admin');    header('location: login.php');

用户列表显示urs.php

    <?php    require '../db.func.php';    require '../tools.func.php';    require 'auth.php';    // 1. 写sql查询    $prefix = getdbprefix();    $sql = "lect id, urname, age, name, email, phone, created_at                    from {$prefix}ur order by created_at desc";    // 2. 执行查询    $res = query($sql);    // 3. 遍历结果    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <div class="row">                        <div class="col-10">                            <h4 class="card-title ">所有用户</h4>                            <p class="card-category"> 用户列表</p>                        </div>                        <div class="col-2">                            <a href="ur_add.php" class="btn btn-round btn-info" style="margin-left: 20px;">添加用户</a>                        </div>                    </div>           明星护肤     </div>                <div class="card-body">                    <p><?php if (hasinfo()) echo getinfo(); ?></p>                    <div class="table-responsive">                        <table class="table table-hover">                            <thead class=" text-primary">                            <th>                                id                            </th>                            <th>                                用户名                            </th>                            <th>                                姓名                            </th>                            <th>                                年龄                            </th>                            <th>                                邮箱                            </th>                            <th>                                联系电话                            </th>                            <th>                                注册时间                            </th>                            <th>                                操作                            </th>                            </thead>                            <tbody>                            <?php foreach ($res as $ur): ?>                            <tr>                                <td>                                    <?php echo $ur['id']; ?>                                </td>                                <td>                    <?php echo $ur['urname']; ?>                                </td>                                <td>                    <?php echo $ur['name']; ?>                                </td>                                <td>                    <?php echo $ur['age']; ?>                                </td>                                <td>                    <?php echo $ur['email']; ?>                                </td>                                <td>                    <?php echo $ur['phone']; ?>                                </td>                                <td>                    <?php echo $ur['created_at']; ?>                                </td>                                <td>                                    <a href="ur_edit.php?id=<?php echo $ur['id']; ?>">编辑</a>                                    |                                    <a href="ur_del.php?id=<?php echo $ur['id']; ?>">删除</a>                                </td>                            </tr>                            <?php endforeach; ?>                            </tbody>                        </table>                    </div>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

添加用户ur_add.php

    <?php    require '../tools.func.php';    require '../db.func.php';    require 'auth.php';    if (!empty($_post['urname'])) {        // 1. 接收post数据        $urname = htmlentities($_post['urname']);        $password = htmlentities($_post['password']);        $confirmpass = htmlentities($_post['confirmpass']);        $name = htmlentities($_post['name']);        $age = htmlentities($_post['age']);        $email = htmlentities($_post['email']);        $phone = htmlentities($_post['phone']);        $created_at = date('y-m-d h:i:s');        $prefix = getdbprefix();        // 2. 验证密码输入是否一致        if ($password != $confirmpass) {            tinfo('两次密码输入不一致');        } el {            $password = md5($password);        // 3. 写sql语句            $sql = 如何打开摄像头"inrt into {$prefix}ur(urname, password, age, name, email, phone, created_at)                            values('$urname', '$password', '$age', '$name', '$email', '$phone', '$created_at')";        // 4. 执行添加,如果成功,显示成功信息            if (execute($sql)) {                tinfo('添加成功');            } el {          tinfo('添加失败');            }        }    }    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <h4 class="card-title">添加用户</h4>                    <p class="card-category">添加一个用户</p>                </div>                <div class="card-body">                    <?php if (hasinfo()) echo getinfo(); ?>                    <form action="ur_add.php" method="post">                        <div class="row">                            <div class="col-md-4">                                <div class="form-group">                                    <label class="bmd-label-floating">用户名</label>                                    <input type="text" name="urname" class="form-control">                                </div>                            </div>                            <div class="col-md-4">                                <div class="form-group">                                    <label class="bmd-label-floating">密码</label>                                    <input type="password" name="password" class="form-control">                                </div>                            </div>                            <div class="col-md-4">                                <div class="form-group">                                    <label class="bmd-label-floating">确认密码</label>                                    <input type="password" name="confirmpass" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">姓名</label>                                    <input type="text" name="name" class="form-control">                                </div>                            </div>                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">年龄</label>                                    <input type="number" name="age" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">联系电话</label>                                    <input type="text" name="phone" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">电子邮箱</label>                                    <input type="email" name="email" class="form-control">                                </div>                            </div>                        </div>                        <button type="submit" class="btn btn-primary pull-right">添加用户</button>                        <div class="clearfix"></div>                    </form>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

修改用户信息ur_edit.php

    <?php    require '../db.func.php';    require '../tools.func.php';    require 'auth.php';    // 1. 接收id    $id = intval($_get['id']);    if (empty($id)) {        header('location: urs.php');    }    // 2. 根据id查询用户    $prefix = getdbprefix();    $sql = "lect id,urname,age,email,phone,name                     from {$prefix}ur where id = '$id'";    $current_ur = queryone($sql);    if (empty($current_ur)) {      header('location: urs.php');    }    // 3. 将查询出的用户的数据放入到表单当中    // 4. 判断是否为post提交    if (!empty($_post['name'])) {      // 5. 接收post数据        $name = htmlentities($_post['name']);        $age = htmlentities($_post['age']);        $email = htmlentities($_post['email']);        $phone = htmlentities($_post['phone']);        // 6. 更新数据记录        $sql = "update {$prefix}ur                         t name = '$name', age = '$age', email = '$email', phone = '$phone'                        where id = '$id'";        if (execute($sql)) {        $current_ur = array_merge($current_ur, $_post);            tinfo('更新成功');        } el {            tinfo('更新失败');        }        // 7. 显示结果    }    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <h4 class="card-title">修改用户</h4>                    <p class="card-category">修改一个用户</p>                </div>                <div class="card-body">                    <?php if (hasinfo()) echo getinfo(); ?>                    <form action="ur_edit.php?id=<?php echo $id; ?>" method="post">                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">用户名</label>                                    <input type="text" name="urname" value="<?php echo $current_ur['urname']; ?>" disabled class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">姓名</label>                                    <input type="text" name="name" value="<?php echo $current_ur['name']; ?>" class="form-control">                                </div>                            </div>                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">年龄</label>                                    <input type="number" name="age" value="<?php echo $current_ur['age']; ?>" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">联系电话</label>                                    <input type="text" name="phone" value="<?php echo $current_ur['phone']; ?>" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label class="bmd-label-floating">电子邮箱</label>                                    <input type="email" name="email" value="<?php echo $current_ur['email']; ?>" class="form-control">                                </div>                            </div>                        </div>                        <button type="submit" class="btn btn-primary pull-right">更新信息</button>                        <div class="clearfix"></div>                    </form>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

删除用户ur_del.php

    <?php    /**     * created by phpstorm.     * date: 2019/1/24     * time: 10:49     */    require '../db.func.php';    require '../tools.func.php';    require 'auth.php';    // 1. 接收id    $id = intval($_get['id']);    // 2. 从数据库当中删除对应的数据    $prefix = getdbprefix();    $sql = "delete from {$prefix}ur where id = '$id'";    if (execute($sql)) {        tinfo('删除成功');    } el {        tinfo('删除失败');    }    // 3. 跳回到列表页    header('location: urs.php');

商品列表products.php

    <?php    require '../tools.func.php';    require 'auth.php';    require '../db.func.php';    $prefix = getdbprefix();    $sql = "lect * from {$prefix}product order by created_at desc ";    $data = query($sql);    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <div class="row">                        <div class="col-10">                            <h4 class="card-title ">所有商品</h4>                            <p class="card-category"> 所有商品列表</p>                        </div>                        <div class="col-2">                            <a href="product_add.php" class="btn btn-round btn-info" style="margin-left: 20px;">添加商品</a>                        </div>                    </div>                </div>                <div class="card-body">                    <div class="table-responsive">                        <table class="table table-hover" style="table-layout:fixed; ">                            <thead class=" text-primary">                            <th width="5%">                                id                            </th>                            <th>                                商品编号                            </th>                            <th>                                商品名称                            </th>                            <th>                                商品描述                            </th>                            <th>                                商品库存                            </th>                            <th>                                商品单价                            </th>                            <th>                                商品上架时间                            </th>                            <th>                                编辑                            </th>                            </thead>                            <tbody>                <?php foreach ($data as $pro): ?>                                <tr>                                    <td>                        <?php echo $pro['id']; ?>                                    </td>                                    <td>                        <?php echo $pro['code']; ?>                                    </td>                                    <td>                        <?php echo $pro['name']; ?>                                    </td>                                    <td>                        <?php echo mb_substr($pro['description'], 0, 8, 'utf-8') . '...'; ?>                                    </td>                                    <td>                        <?php echo $pro['stock']; ?>                                    </td>                                    <td>                        <?php echo $pro['price']; ?>                                    </td>                                    <td>                        <?php echo $pro['created_at']; ?>                                    </td>                                    <td>                                        <a href="#">编辑</a>                                        |                                        <a href="#">删除</a>                                    </td>                                </tr>                <?php endforeach; ?>                            </tbody>                        </table>                    </div>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

添加商品product_add.php

    <?php    require '../tools.func.php';    require 'auth.php';    require '../db.func.php';    // 1. 判断是否为post提交    if (!empty($_post['name'])) {      // 2. 接收post数据        $name = htmlentities($_post['name']);        $code = htmlentities($_post['code']);        $price = doubleval($_post['price']);        $stock = intval($_post['stock']);        $description = htmlentities($_post['description']);        $created_at = date('y-m-d h:i:s');        // 3. 写sql语句        $prefix = getdbprefix();        $sql = "inrt into {$prefix}product(name, code, price, stock, description, created_at)                        values('$name', '$code', '$price', '$stock', '$description', '$created_at')";        // 4. 执行插入        if (execute($sql)) {            tinfo('添加成功');        } el {        tinfo('添加失败');        }        // 5. 显示结果    }    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <h4 class="card-title">添加商品</h4>                    <p class="card-category">添加一个商品</p>                </div>                <div class="card-body">                    <?php if (hasinfo()) echo getinfo(); ?>                    <form action="product_add.php" method="post">                        <div class="row">                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">商品名称</label>                                    <input type="text" name="name" class="form-control">                                </div>                            </div>                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">商品单价</label>                                    <input type="number" name="price" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">商品库存</label>                                    <input type="number" name="stock" class="form-control">                                </div>                            </div>                            <div class="col-md-6">                                <div class="form-group">                                    <label class="bmd-label-floating">商品编号</label>                                    <input type="text" name="code" class="form-control">                                </div>                            </div>                        </div>                        <div class="row">                            <div class="col-md-12">                                <div class="form-group">                                    <label>商品描述</label>                                    <div class="form-group bmd-form-group">                                        <textarea name="description" class="form-control" rows="5"></textarea>                                    </div>                                </div>                            </div>                        </div>                        <button type="submit" class="btn btn-primary pull-right">添加商品</button>                        <div class="clearfix"></div>                    </form>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

购物车列表页carts.php

    <?php    require '../tools.func.php';    require '../db.func.php';    require 'auth.php';    $prefix = getdbprefix();    $sql = "lect id, price, quantity, uid, created_at from {$prefix}cart order by created_at desc";    $back_cart_data = [];    $cart = query($sql);    foreach ($cart as $c) {      $sql = "lect urname from {$prefix}ur where id = '{$c['uid']}'";      $ur = queryone($sql);      $c['urname'] = $ur['urname'];      $back_cart_data[] = $c;    }    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <div class="row">                        <div class="col-12">                            <h4 class="card-title ">所有购物车</h4>                            <p class="card-category"> 所有购物车列表</p>                        </div>                    </div>                </div>                <div class="card-body">                    <div class="table-responsive">                        <table class="table table-hover">                            <thead class=" text-primary">                            <th>                                id                            </th>                            <th>                                购物车用户                            </th>                            <th>                                商品总量                            </th>                            <th>                                购物车总价                            </th>                            <th>                                添加时间                            </th>                            <th>                                编辑                            </th>                            </thead>                            <t行楷书body>                            <?php foreach ($back_cart_data as $cart): ?>                            <tr>                                <td>                                    <?php echo $cart['id']; ?>                                </td>                                <td>                    <?php echo $cart['urname']; ?>                                </td>                                <td>                    <?php echo $cart['quantity']; ?>                                </td>                                <td>                    <?php echo $cart['price']; ?>                                </td>                                <td>                    <?php echo $cart['created_at']; ?>                                </td>                                <td>                                    <a href="">删除</a>                                </td>                            </tr>                            <?php endforeach; ?>                            </tbody>                        </table>                    </div>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

订单列表orders.php

    <?php    require '../tools.func.php';    require 'auth.php';    require '../db.func.php';    $prefix = getdbprefix();    $sql = "lect id, uid, price, quantity, created_at                     from {$prefix}order order by created_at desc";    $orders = query($sql);    require 'header.php';    ?>    <div class="row">        <div class="col-md-12">            <div class="card">                <div class="card-header card-header-primary">                    <div class="row">                        <div class="col-12">                            <h4 class="card-title ">所有订单</h4>                            <p class="card-category"> 所有订单列表</p>                        </div>                    </div>                </div>                <div class="card-body">                    <div class="table-responsive">                        <table class="table table-hover">                            <thead class=" text-primary">                            <th>                                id                            </th>                            <th>                                下单用户                            </th>                            <th>                                订单价格                            </th>                            <th>                                订单商品数量                            </th>                            <th>                                下单时间                            </th>                            </thead>                            <tbody>                            <?php foreach($orders as $order): ?>                            <tr>                                <td>                                    <?php echo $order['id']; ?>                                </td>                                <td>                    <?php echo $order['uid']; ?>                                </td>                                <td>                    <?php echo $order['price']; ?>                                </td>                                <td>                      <?php echo $order['quantity']; ?>                                </td>                                <td>                    <?php echo $order['created_at']; ?>                                </td>                            </tr>                            <?php endforeach; ?>                            </tbody>                        </table>                    </div>                </div>            </div>        </div>    </div>    <?php    require 'footer.php';    ?>

本文发布于:2023-04-08 02:52:45,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/zuowen/0ccfb1041c130707cbb8340f28eb126f.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

本文word下载地址:电子商城项目开发(后台功能模块开发).doc

本文 PDF 下载地址:电子商城项目开发(后台功能模块开发).pdf

标签:商品   密码   用户   购物车
相关文章
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图