销售管理系统 | 数据库课设

news2024/10/5 5:57:47

文章目录

      • 前言
      • 项目介绍
        • E-R图
        • 表结构
        • 系统总体框架
      • 搭建项目
        • 环境介绍
        • 创建网站
        • 主页
        • 连接数据库
        • 注册功能
        • 登录功能
        • 管理员登录功能
        • 注销登录功能
        • 个人信息
        • 后台管理
        • 查看供应商名单
          • 删除功能
          • 修改功能
        • 登记货物信息功能
        • 购买商品功能
        • 总源码
      • 教训
      • 总结

前言


  1. 为了期末的数据库课设,这是最初的目的。在进行这个项目之前,我已经完成了数据库的相应实验,对数据库的操作有一定的了解。整个项目时间:1月8日-1月13日,期间还去考了个科三。
  2. 前些日子分别用phpstudy和云服务器搭建了开源的web项目(PHP+MySQL+Apache),简单地熟悉了网站的开发流程,熟悉前端、后端和数据库之间的交互。
  3. 参考视频:【PHP动态网站开发-哔哩哔哩】 ,根据视频的顺序,完善我自己的项目需求,跟视频的项目功能点类似,但不是同一个项目。 这是一个较为简略的代码,只简单地完成了需求,欢迎有需要的同学进行加工完善,源码放在了文章末尾。

项目介绍


E-R图

一个客户对应一个信誉等级,所以客户与信誉等级是一对一关系。
一个客户可以订购多个订单,一个订单对应一个客户,所以客户与订单是一对多关系。
一个订单可以订购一个商品,一个商品可以被多个订单订购,所以商品和订单是一对多关系。
一个商品对应一种商品类型,一个商品类型有多种商品,所以商品类型和商品是一对多关系。
一个供应商可以提供多个商品,一个商品能被多个供应商供应,所以供应商和商品是多对多关系。

在这里插入图片描述

表结构

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

系统总体框架

在这里插入图片描述

搭建项目


环境介绍

本来是用SqlServer做实验的,但是phpstudy搭配这个很麻烦,就改用mysql了。
数据库图形界面:sqlyog
php编辑器:phpstorm
数据库:mysql 5.7.26
php版本:php 7.3.4
web服务器:Apache 2.4.39

创建网站

可以看《毒鸡汤 | PHPStudy搭建web项目》。

  1. 开启服务
    在这里插入图片描述

  2. 创建网站,最好一个项目一个,这样不会混
    在这里插入图片描述

  3. 打开网站的根目录:【Sales-管理-打开根目录】。这个项目的文件都需要放在这个文件夹下
    在这里插入图片描述

  4. 创建数据库,我后面用到的数据库名是Sale,账号密码后面会用到,连接数据库也需要用到,先提个醒。
    在这里插入图片描述

  5. 导入sale.sql文件:【数据库-Sale-操作-导入】
    在这里插入图片描述

主页

主页面index.php
在这里插入图片描述
源码

<?php
    //开启会话
    session_start();
?>
<!--首页前端页面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水有限公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
        .login{font-size: 16px;color: #2d6a88}
        .logout{margin-left:20px;margin-bottom: 15px }
        .logout a{color: darkgreen;text-decoration: none}
        .logout a:hover{text-decoration: underline}
    </style>
</head>
<body>
<div  class="main">
    <h1>欢迎来到山水有限公司</h1>
    <?php
        if(isset($_SESSION['loginusername'])&&$_SESSION['loginusername']<>''){
    ?>
    <div class="login">
        当前登录者:<?php echo $_SESSION['loginusername'];?>
        <span class="logout">
            <a href="logout.php">注销登录</a>
        </span>
    </div>
    <?php
        }
    ?>
    <h2>
        <a href="index.php" class="current">首页</a>
        <a href="admin_login.php">管理员登录</a>
        <a href="zhuce.php">注册账号</a>
        <a href="login.php">登录账号</a>
        <a href="modify.php">个人信息</a>
        <a href="houtai.php">后台管理</a>
    </h2>
</div>
</body>
</html>

连接数据库

创建conn_database.php文件,使用刚刚创建的数据库的用户名和密码。

<?php
    //连接数据库服务器
    $conn=mysqli_connect("localhost","admin","12345678","Sale");
    if(!$conn){
        die("连接数据库服务器失败");
    }
    else{
        echo '';
//        echo "success";
    }

注册功能

注册页面zhuce.php
在这里插入图片描述
源码

<!--用户注册的前端界面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
    </style>
</head>
<body>
<div  class="main">
    <h1>注册账号</h1>
    <h2>
        <a href="index.php">首页</a>
        <a href="admin_login.php">管理员登录</a>
        <a href="zhuce.php" class="current">注册账号</a>
        <a href="login.php">登录账号</a>
        <a href="modify.php">个人信息</a>
        <a href="houtai.php">后台管理</a>
    </h2>
    <form action="zhuce_post.php" method="post" onsubmit="return check()">
        <table align="center" border="1" style="border-collapse: collapse" cellpadding="10" cellspacing="0">
            <tr>
                <td>身份</td>
                <td>
                    <input name="identity" type="radio" checked value="customer">客户
                    <input name="identity" type="radio" value="supplier">供应商
                </td>
            </tr>
            <tr>
                <td>名称</td>
                <td><input name="username"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" name="password"></td>
            </tr>
            <tr>
                <td>电话</td>
                <td><input name="tele"></td>
            </tr>
            <tr>
                <td>地址</td>
                <td><input name="addr"></td>
            </tr>
        </table>
        <p>
            <input type="submit" value="提交">
        </p>
    </form>
</div>
<!--表单验证-->
<script>
    function check(){
        //用户名验证
        let username=document.getElementsByName('username')[0].value.trim();
        let usernameReg=/^[a-zA-Z0-9]{1,8}$/;
        if(!usernameReg.test(username)){
            alert("用户名必填,且只能由数字或者字符构成,长度为1-8个字符");
            return false;
        }
        //其他的验证可以自己完善
    }
</script>
</body>
</html>

提交注册zhuce_post.php,将前端的注册页面的信息发送到后端进行处理,比如对数据进行验证后发送到数据库进行保存。

<?php
    //如果当前有用户,注销当前账号
    include_once 'logout.php';

    //设置字符集
    header("Content-Type:text/html;charset=utf-8");

    //后端获取前端注册的表单信息
    $identity=$_POST['identity'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $tele=$_POST['tele'];
    $addr=$_POST['addr'];

    //验证:用户名和密码不能为空
    if(!strlen($username)||!strlen($password)){
        echo "<script>alert('用户名或密码不能为空');history.back();</script>";
        exit;
    }

    //连接数据库
    include_once "conn_database.php";

    //设置字符集
    mysqli_query($conn,"set names utf-8");

    //验证:用户名是否被占用
    $sql="select * from $identity where username='$username'";
    $result=mysqli_query($conn,$sql);//返回一个结果集
    $number=mysqli_num_rows($result);
    if($number){
        echo "<script>alert('此用户名已被占用,请返回重新输入');history.back();</script>";
        exit;//这下面的代码不会执行
    }

    //将注册信息插入数据库
    $sql="insert into $identity (username,password,tele,addr) values ('$username','$password','$tele','$addr');";
    $result=mysqli_query($conn,$sql);
    if($result){
        echo "<script>alert('注册成功');location.href='index.php';</script>";
    }
    else{
        echo "<script>alert('注册失败,请重新注册');history.back();</script>";
    }

?>

登录功能

登录页面login.php
在这里插入图片描述

<?php
    session_start();
?>
<!--用户登录的前端界面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
        .login{font-size: 16px;color: #2d6a88}
        .logout{margin-left:20px;margin-bottom: 15px }
        .logout a{color: darkgreen;text-decoration: none}
        .logout a:hover{text-decoration: underline}
    </style>
</head>
<body>
<div  class="main">
    <h1>登录账号</h1>
    <?php
    if(isset($_SESSION['loginusername'])&&$_SESSION['loginusername']<>''){
        ?>
        <div class="login">
            当前登录者:<?php echo $_SESSION['loginusername'];?>
            <span class="logout">
            <a href="logout.php">注销登录</a>
        </span>
        </div>
        <?php
    }
    ?>
    <h2>
        <a href="index.php">首页</a>
        <a href="admin_login.php">管理员登录</a>
        <a href="zhuce.php">注册账号</a>
        <a href="login.php" class="current">登录账号</a>
        <a href="modify.php">个人信息</a>
        <a href="houtai.php">后台管理</a>
    </h2>
    <form action="login_post.php" method="post" onsubmit="return check()">
        <table align="center" border="1" style="border-collapse: collapse" cellpadding="10" cellspacing="0">
            <tr>
                <td>身份</td>
                <td>
                    <input name="identity" type="radio" checked value="customer">客户
                    <input name="identity" type="radio" value="supplier">供应商
                </td>
            </tr>
            <tr>
                <td>名称</td>
                <td><input name="username"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" name="password"></td>
            </tr>
        </table>
        <p>
            <input type="submit" value="提交">
        </p>
    </form>
</div>
<!--表单验证-->
<script>
    function check(){
        //用户名验证
        let username=document.getElementsByName('username')[0].value.trim();
        let usernameReg=/^[a-zA-Z0-9]{1,8}$/;
        if(!usernameReg.test(username)){
            alert("用户名必填,且只能由数字或者字符构成,长度为1-8个字符");
            return false;
        }
        //其他验证可以自行完善
    }
</script>
</body>
</html>

提交登录post_login.php

<?php
    /*
     * 使用session会话:
     * 作用:管理权限或者登录标志。
     * session是全局数组,当前所有站点都可以使用。
     * 工作机制:系统为每一个用户分配一个sessionid
    */

    //重新登录的话,自动注销
    include_once 'logout.php';

    //开启session
    session_start();

    //设置字符集
    header("Content-Type:text/html;charset=utf-8");

    //后端获取前端注册的表单信息
    $identity=$_POST['identity'];
    $username=$_POST['username'];
    $password=$_POST['password'];

    //验证:用户名和密码不能为空
    if(!strlen($username)||!strlen($password)){
        echo "<script>alert('用户名或密码不能为空');history.back();</script>";
        exit;
    }

    //连接数据库服务器
    include_once "conn_database.php";

    //设置字符集
    mysqli_query($conn,"set names utf-8");

    //查询用户名和密码是否正确
    $sql="select * from $identity where username='$username' and password='$password'";
    $result=mysqli_query($conn,$sql);//返回一个结果集
    $number=mysqli_num_rows($result);
    if($number){
        //全局变量
        $_SESSION['loginusername']=$username;
        $_SESSION['identity']=$identity;
        //跳转到首页
        echo "<script>alert('登录成功');location.href='index.php';</script>";
    }
    else{
        //登录失败,销毁
        unset($_SESSION['loginusername']);
        echo "<script>alert('登录失败');history.back();</script>";
    }
?>

管理员登录功能

管理员登录页面,文件名admin_login.php
在这里插入图片描述

<?php
    session_start();
?>
<!--管理员登录的前端界面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
    </style>
</head>
<body>
<div  class="main">
    <h1>管理员登录</h1>
    <h2>
        <a href="index.php">首页</a>
        <a href="admin_login.php" class="current">管理员登录</a>
        <a href="zhuce.php">注册账号</a>
        <a href="login.php">登录账号</a>
        <a href="modify.php">个人信息</a>
        <a href="houtai.php">后台管理</a>
    </h2>
    <form action="admin_login_post.php" method="post" onsubmit="return check()">
        <table align="center" border="1" style="border-collapse: collapse" cellpadding="10" cellspacing="0">
            <tr>
                <td>名称</td>
                <td><input name="username"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input type="password" name="password"></td>
            </tr>
        </table>
        <p>
            <input type="submit" value="提交">
        </p>
    </form>
</div>
</body>
</html>

提交管理员登录admin_login_post.php

<?php
    session_start();

    //将管理员的账号密码放在customer表,为了能在个人信息那显示,但不用连接数据库直接判断账号密码
    $username=$_POST['username'];
    $password=$_POST['password'];
    if($username=="admin111" && $password=="admin111"){
        //设置管理员的标志
        $_SESSION['identity']='customer';
        $_SESSION['isAdmin']='admin';
        $_SESSION['loginusername']=$username;
        //跳转到首页
        echo "<script>alert('欢迎管理员登录');location.href='index.php';</script>";
    }
    else{
        //销毁会话
        unset($_SESSION['isAdmin']);
        unset($_SESSION['loginusername']);
        echo "<script>alert('登录失败');history.back();</script>";
    }
?>

注销登录功能

注销登录页面logout.php
在这里插入图片描述

<?php
    //实现注销登录

    session_start();
    //销毁会话
    session_destroy();
//    //跳转回主页
//    header("location:login.php");

个人信息

展示登录者的个人信息modify.php
在这里插入图片描述

<?php
    session_start();
    if(!( isset($_SESSION['loginusername']) )){
        echo "<script>alert('请先登录');location.href='login.php';</script>";
}
?>
<!--个人信息的前端界面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
    </style>
</head>
<body>
<div  class="main">
    <h1>个人信息</h1>
    <h2>
        <a href="index.php">首页</a>
        <a href="admin_login.php">管理员登录</a>
        <a href="zhuce.php">注册账号</a>
        <a href="login.php">登录账号</a>
        <a href="modify.php" class="current">个人信息</a>
        <a href="houtai.php">后台管理</a>
    </h2>
    <!--查询数据库内容-->
    <?php
        //连接数据库
        include_once 'conn_database.php';
        //接收参数
        $username=$_GET['username'];
        $identity=$_GET['identity'];
        if($username&&$identity){
            //说明有username参数,是管理员修改别人的信息
            $sql="select * from $identity where username='$username'";
        }
        else{
            //说明是用户登录后自己修改的
            $sql="select * from ".$_SESSION['identity']." where username='".$_SESSION['loginusername']."'";
        }
        $result=mysqli_query($conn,$sql);
        $number=mysqli_num_rows($result);
        $info=mysqli_fetch_array($result);
    ?>
    <form action="modify_post.php" method="post" onsubmit="return check()">
        <table align="center" border="1" style="border-collapse: collapse" cellpadding="10" cellspacing="0">
            <tr>
                <td>身份</td>
                <td>
                    <?php
                        if($identity=='supplier'){
                            echo '供应商';
                        }
                        elseif($_SESSION['isAdmin']=='admin' and $_SESSION['identity']=='customer'){
                            echo '管理员';
                        }
                        else{
                            echo '客户';
                        }
                    ?>
                </td>
            </tr>
            <tr>
                <td>名称</td>
                <td><input name="username" value="<?php echo $info['username'];?>"></td>
            </tr>
            <tr>
                <td>密码</td>
                <td><input name="password" value="<?php echo $info['password'];?>"></td>
            </tr>
            <tr>
                <td>电话</td>
                <td><input name="tele" value="<?php echo $info['tele'];?>"></td>
            </tr>
            <tr>
                <td>地址</td>
                <td><input name="addr" value="<?php echo $info['addr'];?>"></td>
            </tr>
        </table>
        <p>
            <input type="submit" value="提交">
        </p>
    </form>
</div>
<!--表单验证-->
<script>
    function check(){
        //密码验证
        let password=document.getElementsByName('username')[0].value.trim();
        let passwordReg=/^[a-zA-Z0-9]{1,8}$/;
        if(!passwordReg.test(password)){
            alert("密码必填,且只能由数字或者字符构成,长度为1-8个字符");
            return false;
        }
        //其他验证可以自行完善
    }
</script>
</body>
</html>

后台管理

这个功能的权限很分明,文件名为houtai.php
在这里插入图片描述

<?php
    session_start();
?>
<!--后台管理前端页面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水有限公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        h3{font-size: 15px}
        h3 a{color: darkgrey;text-decoration: none;margin-right: 15px}
        h3 a:last-child{margin-right: 0}
        h3 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
        .logout a{color: darkgreen;text-decoration: none}
        .logout a:hover{text-decoration: underline}
    </style>
</head>
<body>
<div  class="main">
    <h1>后台管理</h1>
    <h2>
        <a href="index.php">首页</a>
        <a href="admin_login.php">管理员登录</a>
        <a href="zhuce.php">注册账号</a>
        <a href="login.php">登录账号</a>
        <a href="modify.php">个人信息</a>
        <a href="houtai.php" class="current">后台管理</a>
    </h2>
    <h3>
        <a href="check_supplier.php">查看供应商名单</a>
        <a href="check_customer.php">查看客户名单</a>
        <a href="check_credit.php">查看客户信誉</a>
        <a href="insert_goods.php">登记货物信息</a>
        <a href="check_goods.php">购买商品</a>
        <a href="check_orders.php">查看订单列表</a>
    </h3>
</div>
</body>
</html>

查看供应商名单

查看供应商名单页面check_supplier.php
在这里插入图片描述

<?php
    session_start();
?>
<!--查看供应商名单前端页面-->
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>山水有限公司销售管理系统</title>
    <style>
        .main{width: 80%;margin: 0 auto;text-align: center}
        h2{font-size: 20px}
        h2 a{color: #2d6a88;text-decoration: none;margin-right: 15px}
        h2 a:last-child{margin-right: 0}
        h2 a:hover{color: #3a87ad;text-decoration: underline}
        h3{font-size: 15px}
        h3 a{color: darkgrey;text-decoration: none;margin-right: 15px}
        h3 a:last-child{margin-right: 0}
        h3 a:hover{color: #3a87ad;text-decoration: underline}
        .current{color: darkcyan}
        .logout a{color: darkgreen;text-decoration: none}
        .logout a:hover{text-decoration: underline}
    </style>
</head>
<body>
<div  class="main">
    <?php
        include_once 'conn_database.php';
        //管理员权限判断
        include_once 'quanxian.php';
        $sql="select * from supplier order by num;";
        $result=mysqli_query($conn,$sql);
    ?>
    <h1>后台管理</h1>
    <h2>
        <a href="index.php">首页</a>
        <a href="admin_login.php">管理员登录</a>
        <a href="zhuce.php">注册账号</a>
        <a href="login.php">登录账号</a>
        <a href="modify.php">个人信息</a>
        <a href="houtai.php" class="current">后台管理</a>
    </h2>
    <h3>
        <a href="check_supplier.php" class="current">查看供应商名单</a>
        <a href="check_customer.php">查看客户名单</a>
        <a href="check_credit.php">查看客户信誉</a>
        <a href="insert_goods.php">登记货物信息</a>
        <a href="check_goods.php">购买商品</a>
        <a href="check_orders.php">查看订单列表</a>
    </h3>
    <table border="1" cellspacing="0" cellpadding="10" style="border-collapse: collapse" align="center" width="70%">
        <tr>
            <td>序号</td>
            <td>供应商号</td>
            <td>供应商名称</td>
            <td>联系电话</td>
            <td>地址</td>
            <td>操作</td>
        </tr>
        <?php
            $i=1;
            while($info=mysqli_fetch_array($result)){
        ?>
        <tr>
            <td><?php echo $i;?></td>
            <td><?php echo "S00".$info['num'];?></td>
            <td><?php echo $info['username'];?></td>
            <td><?php echo $info['tele'];?></td>
            <td><?php echo $info['addr'];?></td>
            <td>
                <a href="javascript:del(<?php echo $info['num']; ?>,'<?php echo $info['username']; ?>');">删除</a>
                <a href="modify.php?identity=supplier&username=<?php echo $info['username']; ?>">修改</a>
            </td>
        </tr>
        <?php
                $i++;
            }
        ?>
    </table>
</div>
<script type="text/javascript">
    //删除按键
    function del(num,username){
        if(confirm('您确定要删除 '+username+' ?')){
            location.href='del.php?identity=supplier&num='+ num +'&username='+username;
        }
    }
</script>
</body>
</html>
删除功能

文件名为del.php,删除选择的用户。

<?php
    //管理员权限判断
    include_once 'quanxian.php';
    //连接数据库
    include_once 'conn_database.php';
    //取传递过来的参数
    $num =$_GET['num'];
    $username=$_GET['username'];
    $identity=$_GET['identity'];
    if(is_numeric($num)){
        //在数据库删除数据
        $sql="delete from $identity where username='$username'";
        $result=mysqli_query($conn,$sql);
        if($result){
            echo "<script>alert('删除会员 $username 成功');history.back();</script>";
        }
        else{
            echo "<script>alert('删除会员 $username 失败');history.back();</script>";
        }
    }
    else{
        echo "<script>alert('参数错误');history.back();</script>";
    }
修改功能

个人信息功能,但是管理员不是查询自己的信息,而是选择的用户信息,因此需要传递选择用户的参数。文件名为modify_post.php

<?php
    session_start();
    //后端获取前端注册的表单信息
    $identity=$_SESSION['identity'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    $tele=$_POST['tele'];
    $addr=$_POST['addr'];

    //验证:密码不能为空
    if(!strlen($password)){
        echo "<script>alert('密码不能为空');history.back();</script>";
        exit;
    }

    //其他的验证自行完善

    //连接数据库
    include_once "conn_database.php";

    //修改个人信息update
    $sql="update $identity set password='$password',addr='$addr',tele='$tele' where username='$username';";
    $result=mysqli_query($conn,$sql);
    if($result){
        echo "<script>alert('修改信息成功');location.href='index.php';</script>";
    }
    else{
        echo "<script>alert('修改信息失败');</script>";
        echo mysqli_error($conn);
    }

查看客户名单功能、查看客户信誉功能、查看订单列表功能和查看供应商名单功能差不多原理,只是SQL语句连接的表不太一样。

登记货物信息功能

同注册功能原理,页面文件名为insert_goods.php,提交登记文件名为insert_goods_post.php
在这里插入图片描述

购买商品功能

显示功能同上,文件名为check_goods.php
在这里插入图片描述
购买页面文件名为bought_goods.php,需要上一个页面传递参数
在这里插入图片描述
提交购买bought_goods_post.php

<?php
session_start();
//权限判断,不是用户不可以下单
if($_SESSION['identity']<>'customer'){
    echo "<script>alert('您不是用户,不可以购买,请登录后购买');location.href='login.php';</script>";
    exit;
}

//接收传递的参数,这个num是商品号
$num=$_GET['num'];
$amount=$_POST['amount'];

//连接数据库
include_once 'conn_database.php';

//查询购买的用户号
$sql="select * from customer where username='".$_SESSION['loginusername']."'";
$result=mysqli_query($conn,$sql);
$info=mysqli_fetch_array($result);
$Cnum=$info['num'];

//将购买的商品信息存入orders表中
$sql="insert into orders(Gnum,Oamount,Cnum)values ('$num','$amount','$Cnum')";
$result=mysqli_query($conn,$sql);
if($result){
    //查询商品的原有数量
    $sql="select * from goods where num='$num';";
    $result=mysqli_query($conn,$sql);
    $info=mysqli_fetch_array($result);
    $amount=$info['amount']-$amount;
    //商品数量相应减少,修改goods表
    $sql="update goods set amount='$amount' where num='$num';";
    $result=mysqli_query($conn,$sql);

    //查询购买用户的credit
    $sql="select Credit,creditgrade.num as Cnum from creditgrade,customer where creditgrade.num=customer.num and username='".$_SESSION['loginusername']."';";
    $result=mysqli_query($conn,$sql);
    $info=mysqli_fetch_array($result);
    $Credit=$info['Credit']+1;
    $num=$info['Cnum'];
    //每购买一次客户信誉增加1,creditgrade表
    $sql="update creditgrade set Credit='$Credit' where num='$num';";
    $result=mysqli_query($conn,$sql);

    echo "<script>alert('购买成功');location.href='check_goods.php';</script>";
}

总源码

放在了百度网盘,欢迎自取

https://pan.baidu.com/s/1ngWJ7S7PIBObhdhn-caV3A?pwd=qnlu 

教训


本来以为某文件不需要了,就在删除之前全选删除了。删完两三分钟才后知后觉,发现后顿时感觉心肌梗塞,想哭又委屈,好在赶紧找方法找回了。实在找不回就只能凭着记忆重新写了。

  1. 先恢复文件
    在这里插入图片描述
  2. 恢复文件后,找该文件的历史版本
    在这里插入图片描述
  3. 找到需要的版本恢复即可
    在这里插入图片描述

总结


  1. 对输入进行限制。由于忽略(没考虑到)或者懒(不想写),没有对输入进行复杂的验证,导致客户端的输入对数据库造成影响。
  2. 权限问题。发现在管理员页面以供应商或者客户的身份重新登录仍保持管理员的权限。因此可以在登录之前,自动注销登录。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/164889.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【C++】STL - Stack - Queue - PriorityQueue使用和模拟实现

&#x1f431;作者&#xff1a;傻响 &#x1f431;专栏&#xff1a;《数据结构_STL》 &#x1f525;格言&#xff1a;你只管努力&#xff0c;剩下的交给时间&#xff01; 目录 栈 Stack介绍 模拟实现 队列 Queue介绍 常用的函数接口介绍 模拟实现 优先级队列 Priority…

【docker18】docker容器之CAdvisor+InfluxDB+Granfana

1.原生命令 1.1操作 命令&#xff1a; docke stats 1.2问题 通过docker stats命令可以很方便的看到当前宿主机上所有容器的CPU&#xff0c;内存以及网络流量控制等数据&#xff0c;一般的小公司够用了。 但是&#xff0c;docker stats统计结果只能是当前宿主机的全部容器&am…

669. 修剪二叉搜索树

669. 修剪二叉搜索树 难度中等 给你二叉搜索树的根节点 root &#xff0c;同时给定最小边界low 和最大边界 high。通过修剪二叉搜索树&#xff0c;使得所有节点的值在[low, high]中。修剪树 不应该 改变保留在树中的元素的相对结构 (即&#xff0c;如果没有被移除&#xff0c…

SourceTree使用方法总结

SourceTree使用方法总结 SourceTree使用总结 添加仓库 mac下从url克隆&#xff1a; windows下从url克隆&#xff1a; 抓取、获取分支信息 抓取&#xff08;mac下的名字&#xff09;获取&#xff08;Windows下的名字&#xff09;指获取服务端git库的变更信息&#xff0c;比如…

基于FPGA的UDP 通信(五)

引言 前文链接&#xff1a; 基于FPGA的UDP 通信&#xff08;一&#xff09; 基于FPGA的UDP 通信&#xff08;二&#xff09; 基于FPGA的UDP 通信&#xff08;三&#xff09; 基于FPGA的UDP 通信&#xff08;四&#xff09; 本文基于FPGA设计千兆以太网通信模块UDP数据发…

12.I/O复用

I/O复用 多进程方式跳过 基于I/O复用的服务器端 接下来讨论并发服务器实现方法的延伸。如果有读者已经跳过第10章和第11章&#xff0c;那就只需把本章内容当做并发服务器实现的第一种方法即可。将要讨论的内容中包含一部分与多进程服务器端的比较&#xff0c;跳过第10章和第…

Android WebView中H5调用Android原生方法

最近做项目&#xff0c;使用webView看一些网页&#xff0c;和网页开发一起找什么方法进行交互&#xff0c;还好解决&#xff0c;分享一下经验。 对于webView的使用就不写了&#xff0c;百度大法好&#xff0c;主要是交互方面&#xff0c;对WebView增加以下代码&#xff1a; bi…

五个了解自己天赋优势的分析工具(一)霍兰德兴趣测试

霍兰德兴趣测试 霍兰德职业兴趣自测&#xff08;Self-Directed Search&#xff09;是由美国职业指导专家霍兰德&#xff08;John Holland&#xff09;根据他本人大量的职业咨询经验及其职业类型理论编制的测评工具。 霍兰德认为&#xff0c;个人职业兴趣特性与职业之间应有一…

74、Beyond RGB: Scene-Property Synthesis with Neural Radiance Fields

简介 List item 论文地址&#xff1a;http://arxiv-export3.library.cornell.edu/abs/2206.04669v1 利用隐式三维表示和神经渲染的最新进展&#xff0c;从综合模型的角度提供了一种新的场景理解方法&#xff0c;能够从新颖的视点渲染照片逼真的RGB图像&#xff0c;而且还能够…

我们怎样才能过好这一生?

文章目录1. 日拱一卒&#xff0c;功不唐捐1.1 适当的时候给自己一个奖励1.2 一个人可能走的更快&#xff0c;但一群人才能走的更远1.3 通过一些事情去逼自己一把1.4 从真理中去感悟1.5 当你面临绝路时2. 梦想的意义不在于实现3. 孤独4. 烦恼5. 别总说来日方长6. 忍和韧性7. 事情…

低成本搭建一台家庭存储服务器:前篇

本篇文章&#xff0c;记录搭建备份服务器的过程。 写在前面 今年考虑专门搭建一台用于数据备份的机器&#xff0c;一来今年外出的需求比较多&#xff0c;历史的设备已经用了几年了&#xff0c;需要有更新的设备来“接力”&#xff1b;二来也想验证方案的靠谱程度&#xff0c;…

k8s之ingress实战小栗子

写在前面 本文接k8s之ingress 。 本文看一个基于ingress作为流量入口的实战例子&#xff0c;架构图如下&#xff1a; 接下来详细看下。 1&#xff1a;部署MariaDB 首先我们需要定义MariaDB使用的configmap&#xff0c;如下&#xff1a; apiVersion: v1 kind: ConfigMap meta…

1587_AURIX_TC275_SMU的部分寄存器3

全部学习汇总&#xff1a; GreyZhang/g_TC275: happy hacking for TC275! (github.com) SMU的章节&#xff0c;剩下的部分全都是寄存器了&#xff0c;没有太多需要特别关注的。因此&#xff0c;接下来选择性整理&#xff0c;完成整个SMU的文档学习整理。 这一页是上一份笔记的…

05_FreeRTOS中断管理

目录 什么是中断 中断相关寄存器 源码实验 什么是中断 简介:让CPU打断正常运行的程序,转而去处理紧急的事件(程序) ,就叫中断。 举例:上课可以比做CPU正常运行的程序,上厕所可以比做中断程序。 中断执行机制,可简单概括为三步: 中断请求:外设产生中断请求(GPIO外部中断、…

【精品】k8s(Kubernetes)cka由基础到实战学法指南

轻松快速学会k8s四招 图1 k8s四招 学完本篇,您会获得什么惊喜? 从初学k8s,到帮助别人学会的过程中,发现朋友们和我,并非不努力,而是没有掌握更好的方法。有方法可让我们学的更快更轻松,这篇文章,以一个networkpolicy的题目,来逐步讲解,帮助大家建立一种,自己可以根…

Java基础语法

文章目录Java 基础语法一、注释1. 注释介绍2. 注释分类3. 注释颜色二、关键字1. 关键字介绍2. 所有关键词三、字面量四、变量1. 变量2. Debug 工具1&#xff09;如何加断点&#xff1f;2&#xff09;如何开启 Debug 运行&#xff1f;3&#xff09;点哪里 ?4&#xff09;看哪里…

ElasticSearch架构之整合ELK

前言本篇文章主要是说ElasticSearch对Logstash、FileBeat、Kibana整合形成ELK的架构&#xff0c;为什么需要整合这个架构呢&#xff1f;一个很重要的原因就是我们开发过程中有相当多的日志需要进行查看&#xff0c;如果我们要查找一个问题需要到多台服务器进行查看那是相当麻烦…

【Java基础知识 4】Java数据类型之间的转换、运算符

本文已收录专栏 &#x1f332;《Java进阶之路》&#x1f332; 目录 &#x1f334;基本数据类型 &#x1f343;01、布尔 &#x1f343;02、byte &#x1f343;03、short &#x1f343;04、int &#x1f343;05、long &#x1f343;06、float &#x1f343;07、double …

C生万物 | 详解程序环境和预处理【展示程序编译+链接全过程】

&#x1f451;作者主页&#xff1a;Fire_Cloud_1 &#x1f3e0;学习社区&#xff1a;烈火神盾 &#x1f517;专栏链接&#xff1a;万物之源——C 文章目录一、程序的翻译环境和执行环境二、详解编译链接1、前言小知识&#x1f50d;2、翻译环境【important】2.1 编译① 预编译【…

【LeetCode每日一题】【2023/1/15】2293. 极大极小游戏

文章目录2293. 极大极小游戏方法1&#xff1a;双指针2293. 极大极小游戏 LeetCode: 2293. 极大极小游戏 简单\color{#00AF9B}{简单}简单 给你一个下标从 0 开始的整数数组 nums &#xff0c;其长度是 2 的幂。 对 nums 执行下述算法&#xff1a; 设 n 等于 nums 的长度&#x…