前言

基于PHP的学生管理系统;

实现 登录、注册、学生信息、修改学生、删除学生、查询学生、添加学生等功能

环境准备

开发平台:PhpStrom2022.1.2 、Phpstudy_pro

数据库:MySQL5.7.26

技术架构

Bootstrap +PHP7.3.4+html5+css3

项目结构

页面展示

1.登录与注册页面

2.首页

3.学生信息

4.修改学生

5.查询学生

6.添加学生

7.管理员信息

8.修改管理员

9.添加管理员

10.查询管理员

11.数据库

注意

1.MySQL 版本5.0以上与8.0以上sql语句有差异,需要调整数据库语句

2.运行项目前提前配置好MySQL数据库

3.本系统实现功能仅供参考


学生信息管理统代码展示

  • 目录

  • 一、登录界面

  • 二、注册页面

  • 三、学生信息

  • 四、添加页面

  • 五、修改页面

  • 六、删除

  • 七、查询页面

  • 八、头部代码

一、登录界面

login.html

login.php

* {margin: 0;padding: 0;}body {background: url(images/backgroud.png);background-repeat: no-repeat;background-size: cover;background-attachment: fixed;}.Login {width: 600px;height: 350px;background: rgb(168, 196, 213);position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin: auto;border-radius: 10px;padding: 20px;box-shadow: 0 0 5px rgba(0,0,0,0.4);}label {display: block;margin-left: 10px;}form {margin: 25px 140px;}h2 {margin-top: 35px;text-align: center;font-size: 25px;color: #000000;}input {width: 220px;height: 30px;background: transparent;margin-top: 30px;border: none;border-bottom: 1px #a77a27 solid;outline: none;color: #000000;font-size: 17px;margin-left: 10px;}input::-webkit-input-placeholder {color: #c3cdd0;}button {width: 98px;height: 30px;border: none;margin-top: 55px;color: white;text-align: center;line-height: 15px;background-image: linear-gradient(to right, #7993d4, #ca71fa);border-radius: 15px;cursor: pointer;}button:hover {box-shadow: 0 0 5px rgba(0,0,0,0.4) inset;}img{width: 27px;height: 27px;position: relative;top: 9px;}

学生管理系统

var b = document.getElementById("btn"); b.onclick = function () { window.location.href="register.html" }var b0 = document.getElementById("btn0");b0.onclick = function () {window.location.href="超级管理员/adminlogin.html"}
query("set names utf8");$user = $_POST['user'];$pwd = $_POST['pwd'];$sql = "SELECT * FROM `admin` WHERE `name` = '{$user}' and `pwd` = '{$pwd}' ";$stmt= $conn->query($sql);$result = mysqli_fetch_array($stmt);if($stmt->num_rows > 0){$_SESSION['user'] = $result[0];echo "alert(\"登录成功!\")";echo "window.location.href='index.php'";}else{echo "alert(\"账号或密码错误,请重新输入!\")";echo "window.location.href='login.html'";}

二、注册页面

register.html

register.php

* {margin: 0;padding: 0;}body {background: url(images/backgroud.png) no-repeat;}.Login {width: 600px;height: 400px;background: rgb(232, 236, 223);position: fixed;top: 0;left: 0;right: 0;bottom: 0;margin: auto;border-radius: 10px;padding: 20px;box-shadow: 0 0 5px rgba(0,0,0,0.4);}label {display: block;margin-left: 10px;}form {margin: 25px 140px;}h2 {margin-top: 35px;text-align: center;font-size: 25px;color: #000000;}input {width: 220px;height: 30px;background: transparent;margin-top: 30px;border: none;border-bottom: 1px #a77a27 solid;outline: none;color: #000000;font-size: 17px;margin-left: 10px;}input::-webkit-input-placeholder {color: #c3cdd0;}button {width: 98px;height: 30px;border: none;margin-top: 50px;margin-left: 40px;color: white;text-align: center;line-height: 15px;background-image: linear-gradient(to right, #7993d4, #ca71fa);border-radius: 15px;cursor: pointer;}button:hover {box-shadow: 0 0 5px rgba(0,0,0,0.4) inset;}span {font-size: 15px;}#btn > a{text-decoration: none;}img{width: 27px;height: 27px;position: relative;top: 9px;}

管理员注册

var b = document.getElementById("btn");b.onclick = function () {window.location.href="login.html"}
query("set names utf8");$user = $_POST['user'];$pwd1 = $_POST['pwd1'];$pwd2 = $_POST['pwd2'];$rows = "select `name` from `admin` where `name` = '{$user}'";$stmt1= $conn->query($rows);$row = mysqli_num_rows($stmt1);if ($row == 1){echo "alert('此用户已存在,请重新输入!')";echo ("window.location.href='register.html'");}elseif ($pwd1 == $pwd2){$sql = "insert into `admin` (`name`, `pwd`) value ('{$user}','{$pwd1}')";$conn->query($sql);echo ("alert('注册成功')");echo ("window.location.href='login.html'");}else{echo "alert('密码错误,请重新输入!')";echo ("window.location.href='register.html'");}$conn->close();

三、学生信息

student.php

学生信息.btn-warning{background-color: #d0455a;}

学生信息展示


0) { // 若表中有数据$number = mysqli_num_rows($result); // 取得数据笔数if(!isset($_GET['p'])){$p=0;}else {$p=$_GET['p'];}$check = $p + 8; // 每页抓取 8 笔数据for ($i = 0; $i = $p && $i < $check) {echo "";echo "";echo "";echo "";echo "";echo "";echo "";echo "";$j = $i+1;}}// for循环}?>
姓名学号性别手机号班级操作
{$stu['user']}{$stu['id']}{$stu['gender']}{$stu['phone']}{$stu['class']}删除修改
  • 第一页
  • 7) { // 判断是否有上一页$last = (floor($p/8)*8)-8;echo "上一页";}elseecho "上一页";?>
  • 7 and $number>$check) // 判断是否有下一页echo "下一页";elseecho "下一页";?>
  • 7) // 判断目前呈现的笔数之后是否还有页面{// 取得最后一页的第一笔数据$final = floor($number/8)*8;echo "最后一页";}elseecho "最后一页";?>

四、添加页面

add.php

add2.php

主页

添加学生






<!---->1班2班3班4班5班6班7班8班9班10班
query("set names utf8");$user = $_POST['user'];$id = $_POST['id'];$gender = $_POST['gender'];$phone = $_POST['phone'];$class = $_POST['class'];$rows = "select `id` from `student` where `id` = '{$id}'";$stmt1= $conn->query($rows);$row = mysqli_num_rows($stmt1);if ($row == 1){echo "alert('此学号已存在,请重新输入!')";echo ("window.location.href='add.php'");}else{$sql = "insert into `student` (`user`,`id`,`gender`,`phone`,`class`) value ('{$user}','{$id}','{$gender}','{$phone}','{$class}')";$stmt= $conn->query($sql);if ($stmt > 0){echo ("alert('添加成功')");echo ("window.location.href='student.php'");}else {echo ("alert('添加失败')");echo ("window.location.href='student.php'");}}$conn->close();

五、修改页面

update.php

update2.php

update3.php

主页

学生信息修改






<!---->1班2班3班4班5班6班7班8班9班10班
query("set names utf8");$user = $_POST['user'];$id = $_POST['id'];$gender = $_POST['gender'];$phone = $_POST['phone'];$class = $_POST['class'];$rows = "select `id` from `student` where `id` = '{$id}' and `user` = '{$user}'";$stmt1= $conn->query($rows);$row = mysqli_num_rows($stmt1);if ($row != 1){echo "alert('学号不可改变,请重新输入!')";echo ("window.location.href='student.php'");}else{$sql = "update `student` set `user` = '{$user}',`gender` = '{$gender}',`phone` = '{$phone}',`class` = '{$class}' where `id` = '{$id}'";$stmt= $conn->query($sql);if ($stmt > 0){echo ("alert('修改成功')");echo ("window.location.href='student.php'");}else {echo ("alert('修改失败')");echo ("window.location.href='student.php'");}}$conn->close();
query("set names utf8");$sql = "SELECT * FROM student WHERE id =".$_GET['id'];$stmt = $conn->query($sql);//返回预处理对象$stu = $stmt->fetch_array(MYSQLI_ASSOC);//返回结果集为数组?>主页

学生信息修改


<input type="text" name="user" class="form-control" value="" placeholder="请输入学生的姓名" required>
<input type="text" name="id" class="form-control" value="" placeholder="请输入学生的学号" required>

<input type="text" name="phone" class="form-control" value="" placeholder="请输入学生的手机号" required>
<!--<select name="class" class="form-control"value="" >1班2班3班4班5班6班7班8班9班10班

六、删除

delete.php

query("set names utf8");$id = $_GET['id'];echo $id;$sql = "delete from `student` where `id` = '{$id}'";$stmt= $conn->query($sql);if ($stmt > 0){echo "alert('删除成功')";echo "window.location.href='student.php'";}else {echo ("alert('删除失败')");echo ("window.location.href='student.php'");}$conn->close();

七、查询页面

select.php

主页th {text-align: center;}label {font-size: 17px;}

学生信息查询


query($sql);while ($row = $result->fetch_assoc()) {echo "";echo "";echo "";echo "";echo "";echo "";echo "";}}?>
姓名学号性别手机号班级
" . $row['user'] . "" . $row['id'] . "" . $row['gender'] . "" . $row['phone'] . "" . $row['class'] . "

八、头部代码

header.php

主页button {top: 7px;right: 15px;}th {text-align: center;}.container {width: 1200px;}.row {line-height: 50px;}.btn-warning {background-color: #d0455a;}body {background-image: url("images/backgroud.png");background-repeat: no-repeat;background-size: cover;background-attachment: fixed;}学生管理系统首页学生信息修改学生查询学生添加学生管理员: