js+php+mysql实现的学生成绩管理系统

js+php的简单学生管理系统,自己建个students的数据库

实现的效果如下图所示:

注册

js+php+mysql实现的学生成绩管理系统_第1张图片

登录

js+php+mysql实现的学生成绩管理系统_第2张图片

系统主页

js+php+mysql实现的学生成绩管理系统_第3张图片

新增页面

js+php+mysql实现的学生成绩管理系统_第4张图片

修改页面

js+php+mysql实现的学生成绩管理系统_第5张图片

注册页面--register.html



    
        
        
        Document
        
        
        
        
    
    
        
注册

注册的php代码-register.php

 0, "msg" => "");
    /*
        在后台再进行一次数据校验
    */
    $username = $_POST['username'];
    $password = $_POST['password'];
    $repassword = $_POST['repassword'];
    $createTime = $_POST['createTime'];

    //1、判断用户名是否存在
    if(!$username){
        $responseData['code'] = 1;
        $responseData['msg'] = "用户名不能为空";
        echo json_encode($responseData);
        exit;
    }
    if(!$password){
        $responseData['code'] = 2;
        $responseData['msg'] = "密码不能为空";
        echo json_encode($responseData);
        exit;
    }

    if($password != $repassword){
        $responseData['code'] = 3;
        $responseData['msg'] = "两次输入不一致";
        echo json_encode($responseData);
        exit;
    }

    $link = mysqli_connect("127.0.0.1", "root", "123456abc");
    if(!$link){
        $responseData['code'] = 4;
        $responseData['msg'] = "服务器忙";
        echo json_encode($responseData);
        exit;
    }
    mysqli_set_charset($link, "utf8");

    mysqli_select_db($link, "qd2002");


    $sql = "SELECT * FROM users WHERE username='{$username}'";
    //mysql result
    $res = mysqli_query($link, $sql);
    //取出一行
    $row = mysqli_fetch_assoc($res);

    //已经注册
    if($row){
        $responseData['code'] = 5;
        $responseData['msg'] = "用户名已经存在";
        echo json_encode($responseData);
        exit;
    }

    //加密
    $str = md5(md5(md5($password).'qianfeng').'xiaoming');

    //准备sql,插入
    $sql2 = "INSERT INTO users (username,password,createTime) VALUES('{$username}','{$str}',{$createTime})";

    $res = mysqli_query($link, $sql2);
    if($res){
        $responseData['msg'] = "注册成功";
        echo json_encode($responseData);
    }else{
        $responseData['code'] = 6;
        $responseData['msg'] = "注册失败";
        echo json_encode($responseData);
        exit;
    }

    mysqli_close($link);
?>

登录页面-login.html



    
        
        
        Document
        
        
        
        
    
    
        
登陆

登录页面-login.php

 0, "msg" => "");
    /*
        在后台再进行一次数据校验
    */
    $username = $_POST['username'];
    $password = $_POST['password'];
     //1、判断用户名是否存在
     if(!$username){
        $responseData['code'] = 1;
        $responseData['msg'] = "用户名不能为空";
        echo json_encode($responseData);
        exit;
    }
    if(!$password){
        $responseData['code'] = 2;
        $responseData['msg'] = "密码不能为空";
        echo json_encode($responseData);
        exit;
    }
    //天龙八部
    //1、链接数据库
    $link = mysqli_connect("127.0.0.1", "root", "123456abc");

    //2、判断数据库是否链接成功
    if(!$link){
        $responseData['code'] = 4;
        $responseData['msg'] = "服务器忙";
        echo json_encode($responseData);
        exit;
    }
    //3、设置访问字符集
    mysqli_set_charset($link, "utf8");

    //4、选择我们要访问的数据库
    mysqli_select_db($link, "qd2002");

    //5、准备sql语句,进行登陆
    //加密
    $str = md5(md5(md5($password).'qianfeng').'xiaoming');
    $sql = "SELECT * from users WHERE username='{$username}' AND password='{$str}'";

    //6、发送sql语句
    $res = mysqli_query($link, $sql);

    //查询,取出其中的行
    $row = mysqli_fetch_assoc($res);
    // var_dump($row);

    if($row){
        
        $responseData['msg'] = "登陆成功";
        echo json_encode($responseData);
        
    }else{
        $responseData['code'] = 5;
        $responseData['msg'] = "用户名或密码错误";
        echo json_encode($responseData);
        exit;
    }

    mysqli_close($link);
?>

主页面 show.html

<    
    
    
        
        
          
        
        
        
        Document
        

    
    
        

学生成绩管理系统

学生学号 学生姓名 语文成绩 数学成绩 英语成绩 操作

通过ajax传数据-ajax.js

export{
    post,
    get,
    ajax
}

function post(){
    var argus =Object.assign({"method" :"post"},...arguments)
    var g = new Ajax(argus);
    g.init();
    g.type()
}

function get(){
    var argus =Object.assign({"method" :"get"},...arguments)
    var g = new Ajax(argus);
    g.init();
    g.type()
}

// function ajax(){
//     var a =new Ajax(...arguments);
//     a.init();
//     a.type();
// }

function ajax(){
    var a = new Ajax(...arguments);
    a.init();
    a.type()
}
class Ajax{
    constructor({method,url,data,success,error}){
        this.method = method;
        this.url = url;
        this.data = data;
        this.success = success;
        this.error = error;
    }
    init(){
        var xhr = null;
        try{
            xhr = new  XMLHttpRequest;
        }catch{
            xhr = new ActiveXObject("XMLHTTP");
        }
        return xhr;
    }

    type(){
        var xhr= this.init()
        var querystring=""
        if(this.data){
            querystring = this.queryString(this.data);
        }
        if(this.method=="get"){
            xhr.open(this.method,this.url+"?"+querystring,true);
            xhr.send();
        }else{
            xhr.open(this.method,this.url,true);
            xhr.setRequestHeader('content-type', "application/x-www-form-urlencoded");
            xhr.send(querystring);
        }

        xhr.onreadystatechange = ()=>{
            if(xhr.readyState ==4){
                if(xhr.status==200){
                    if(this.success){
                        this.success(xhr.responseText)
                    }
                }else{
                    if(this.error){
                        this.error("error"+xhr.status)
                    }
                }
            }
           
        }
    }

    queryString(dataObj){
        var str='';
        for(var attr in dataObj){
            str+=`${attr}=${dataObj[attr]}&`
        }
        return str.substring(0,str.length-1)
    }
}

分页-paging.php

 $page, 
    "count" => $count, 
    "pages" => $pages, 
    "limit" => $limit, 
    "skip" => $skip,
    "userlist" => array()
);
$sql2 = "SELECT * FROM students LIMIT {$skip}, {$limit}";
$res2 = mysqli_query($link, $sql2);
while($row2 = mysqli_fetch_assoc($res2)){
    array_push($msg['userlist'], $row2);
}
echo json_encode($msg);
mysqli_close($link);

?>

数据添加 insert.php

数据删除 delete.php

数据修改-查找update.php

数据修改-更新 update1.php

你可能感兴趣的:(js)