学生信息管理系统
注册,登录(用户,管理员)
login.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>登录界面</title>
<style>
html{
height: 100%;
}
body{
height: 100%;
font-family: 'JetBrains Mono Medium';
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.form-wrapper{
width: 300px;
background-color: rgb(41,45,62);
color: #ffffff;
border-radius: 2px;
padding: 50px;
}
.form-wrapper .header{
text-align: center;
font-size: 35px;
text-transform: uppercase;
line-height: 100px;
}
.form-wrapper .action{
display: flex;
justify-content: center;
}
.form-wrapper .action .btn{
width: 60%;
text-transform: uppercase;
border: 2px solid #FFFFFF;
text-align: center;
line-height: 20px;
border-radius: 20px;
cursor: pointer;
transition:0.2s;
}
</style>
</head>
<body>
<div class="form-wrapper" align="center" >
<div class="header">
用户登录
</div>
<form action="check.php" method="post">
<p>用户名:<input type="text" name="username" placeholder="手机号/邮箱" /></p>
<p>密码:<input type="password" name="password" placeholder="密码可见" /></p>
<br />
<button class="btn">登录</button>
<p>
没有账号?请
<a href="regist.html">注册</a>
</p>
<div style="clear: both;"></div>
</form>
</div>
</body>
</html>
user.html
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>首页</title>
<style>
html{
height: 100%;
}
body{
height: 100%;
font-family: 'JetBrains Mono Medium';
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.form-wrapper{
width: 300px;
background-color: rgb(41,45,62);
color: #ffffff;
border-radius: 2px;
padding: 50px;
}
.form-wrapper .header{
text-align: center;
font-size: 35px;
text-transform: uppercase;
line-height: 100px;
}
.form-wrapper .action{
display: flex;
justify-content: center;
}
.form-wrapper .action .btn{
width: 60%;
text-transform: uppercase;
border: 2px solid #FFFFFF;
text-align: center;
line-height: 50px;
border-radius: 30px;
cursor: pointer;
transition:0.2s;
}
</style>
</head>
<body>
<div class="form-wrapper" align="center" >
<div class="header">
TA反馈系统
</div>
<div class="action">
<div class="btn"><a href="InsertStudent.php">添加学生记录</a></div>
</div>
<div class="action">
<div class="btn"><a href="StudentList.php">查看学生列表</a></div>
</div>
</div>
</body>
</html>
#登录逻辑:check.php(判断是不是管理员,还是普通人
check.php
<?php
header("Content-type: text/html; charset=utf-8");
$username = $_POST['username'];
$password = $_POST['password'];
$is_manager=$_POST['is_manager'];
if ($username == ''){
echo '<script>alert("请输入用户名!");history.go(-1);</script>';
exit(0);
}
if ($password == ''){
echo '<script>alert("请输入密码");history.go(-1);</script>';
exit(0);
}
$conn = new mysqli('localhost','root','root','test');
if ($conn->connect_error){
echo '数据库连接失败!';
exit(0);
}else {
$sql = "select username,password from userinfo where username = '$_POST[username]' and password = '$_POST[password]'";
$result = $conn->query($sql);
$number = mysqli_num_rows($result);
if ($number ) {
if ($username == "admin" && $password == "123456") {
header("Location: index.html");
}else{
echo '<script>window.location="user.html";</script>';
}
}else {
echo '<script>alert("用户名或密码错误!");</script>';
echo '<script>window.location="login.html";';
}
}
?>
用户注册:regist.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>用户注册</title>
<style>
html{
height: 100%;
}
body{
height: 100%;
font-family: 'JetBrains Mono Medium';
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.form-wrapper{
width: 600px;
background-color: rgb(41,45,62);
color: #ffffff;
border-radius: 6px;
padding: 100px;
}
.form-wrapper .header{
text-align: center;
font-size: 35px;
text-transform: uppercase;
line-height: 100px;
}
</style>
</head>
<body>
<div class="form-wrapper" align="center" >
<form action="regist.php" method="post">
<p >用户名<input type="text" name="username" placeholder="" /></p>
<span ></span>
<p >输入密码<input type="password" name="password" placeholder="请输入密码" /></p>
<span >(由6-16的字母、数字、符号组成)</span>
<p >确认密码<input type="password" name="repassword" placeholder="请再次输入密码" /></p>
<p>
我有阅读并同意
<span>《网站服务协议》</span>
</p>
<button type="submit" value="注册" class="psw-btn">立即注册</button>
<p >
已有账号?请
<a href="login.html">登录</a>
</p>
</form>
</div>
</body>
</html>
注册逻辑:regist.php
<?php
header("Content-type: text/html; charset=utf-8");
$username = $_POST['username'];
$password = $_POST['password'];
$repassword = $_POST['repassword'];
if ($username == ''){
echo '<script>alert("请输入用户名!");history.go(-1);</script>';
exit(0);
}
if ($password == ''){
echo '<script>alert("请输入密码");history.go(-1);</script>';
exit(0);
}
if ($password != $repassword){
echo '<script>alert("密码与确认密码应该一致");history.go(-1);</script>';
exit(0);
}
if($password == $repassword){
$conn = new mysqli('localhost','root','root','test');
if ($conn->connect_error){
echo '数据库连接失败!';
exit(0);
}else {
$sql = "select username from userinfo where username = '$_POST[username]'";
$result = $conn->query($sql);
$number = mysqli_num_rows($result);
if ($number) {
echo '<script>alert("用户名已经存在");history.go(-1);</script>';
} else {
$sql_insert = "insert into userinfo (username,password,is_manager) values('$_POST[username]','$_POST[password]','$_POST[is_manager]')";
$res_insert = $conn->query($sql_insert);
if ($res_insert) {
echo '<script>window.location="user.html";</script>';
} else {
echo "<script>alert('系统繁忙,请稍候!');</script>";
}
}
}
}else{
echo "<script>alert('提交未成功!'); history.go(-1);</script>";
}
?>
学生信息管理:
增加学生信息(user )
datasource.php 连接数据库获取数据库信息
<?php
function getConn() {
$host = "localhost";
$user = "root";
$password = "root";
$database = "test";
$conn = mysqli_connect($host, $user, $password, $database);
if ($conn->error) {
die("连接数据库[$database]失败!");
}
return $conn;
}
?>
insertstudent.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>添加学生记录</title>
<style>
fieldset{
background-color: #f1f1f1;
border: none;
border-radius: 2px;
margin-bottom: 6px;
overflow: hidden;
padding: 0 .625em;
}
label{
cursor: pointer;
display: inline-block;
padding: 1px 3px;
text-align: center;
width: 200px;
vertical-align: top;
}
input{
font-size: inherit;
align-items: center;
}
</style>
</head>
<body>
<h1>TA反馈信息系统</h1>
<p style="font-size: 13px;color: blue">  尊敬的各位老师:<br />        大家好!  <br />  
为了更好的了解学生学习情况,对学生学习状态做出及时反馈,请各位老师填写学生信息,本系统会对收集的信息进行数据分析,对学生是否需要特别关注进行等级判定,真诚感谢您的支持,祝您天天愉快,谢谢!</p>
<hr>
<form action="doInsertStudent.php" method="post" >
<h3>学生基本信息</h3>
<fieldset>
<p><label>学生学号:</label>
<input type="number" name="id"></p><br>
<p><label>姓名:</label>
<input type="text" name="name" ></p><br>
<p><label>课程号:</label>
<input type="text" name="ccode"></p><br>
<p><label>课程名:</label><input type="text" name="cname" ></p><br>
<p><label>讲师姓名:</label>
<input type="text" name="instructor"></p><br>
<p><label>助教姓名:</label>
<input type="text" name="taname"></p><br>
<p><label>助教邮箱:</label>
<input type="email" name="taemail"></p><br>
<p><label>助教电话(+86):</label>
<input type="tel" name="taphone"></p><br>
<hr>
<h3>学生学习情况</h3>
<p><label>出勤率低:</label>
<input type="checkbox" name="A"></p><br>
<p><label>未参加期中考试:</label>
<input type="checkbox" name="B"></p><br>
<p><label>期中成绩低于平均分:</label>
<input type="checkbox" name="C"></p><br>
<h3>若成绩低于平均分,请填写期中成绩</h3><br>
<p><label>期中成绩:</label>
<input type="number" name="score"></p><br>
<p><label>多次未交作业:</label><input type="text" name="D"></p><br>
<p><label>其他情况:</label>
<input type="checkbox" name="E"></p><br>
<p><label>需关注级别:</label>
<select name="level" id="level">
<option value="1">level1</option>
<option value="2">level2</option>
<option value="3">level3</option>
</select>
<hr>
<p><label>其他补充:</label>
<input type="text" name="com" style="font-size:20px;padding-top:30px; height:100px;" ></p><br>
<p><input type="submit" value="确定"></p>
<p><input type="reset" value="重置"></p>
</fieldset>
</form>
</body>
</html>
doinsertstudent.php
<?php
require("StudentDao.php");
$id = $_POST['id'];
$name = $_POST['name'];
$ccode = $_POST['ccode'];
$cname= $_POST['cname'];
$instructor = $_POST['instructor'];
$taname = $_POST['taname'];
$taemail = $_POST['taemail'];
$taphone = $_POST['taphone'];
$A = $_POST['A'];
$B= $_POST['B'];
$C= $_POST['C'];
$score = $_POST['score'];
$D= $_POST['D'];
$E = $_POST['E'];
$level = $_POST['level'];
$com = $_POST['com'];
$student = new Student();
$student->setId($id);
$student->setName($name);
$student->setCCode($ccode);
$student->setcname($cname);
$student->setinstructor($instructor);
$student->settaname($taname);
$student->settaemail($taemail);
$student->setTelephone($taphone);
$student->setA($A);
$student->setB($B);
$student->setC($C);
$student->setscore($score);
$student->setD($D);
$student->setE($E);
$student->setlevel($level);
$student->setcom($com);
$retval = insertStudent($student);
if ($retval) {
echo "记录插入成功!";
} else {
echo "记录插入失败!";
}
?>
studentdao.php
<?php
require("Student.php");
require("DataSource.php");
/**
* 查询全部学生
*
* @return array
*/
function findAllStudents() {
// 获得数据库连接
$conn = getConn();
// 定义SQL字符串
$sql = "SELECT * FROM student";
// 执行查询,返回结果集
$result = $conn->query($sql);
// 定义学生数组
$students = array();
// 定义数组下标
$i = 0;
// 遍历结果集
while($row = $result->fetch_assoc()) {
$students[$i] = new Student();
$students[$i]->setId($row['id']);
$students[$i]->setName($row['name']);
$students[$i]->setCCode($row['ccode']);
$students[$i]->setcname($row['cname']);
$students[$i]->setinstructor($row['instructor']);
$students[$i]->settaname($row['taname']);
$students[$i]->settaemail($row['taemail']);
$students[$i]->setTelephone($row['taphone']);
$students[$i]->setA($row['A']);
$students[$i]->setB($row['B']);
$students[$i]->setC($row['C']);
$students[$i]->setscore($row['score']);
$students[$i]->setD($row['D']);
$students[$i]->setE($row['E']);
$students[$i]->setlevel($row['level']);
$students[$i]->setcom($row['com']);
$i++;
}
return $students;
}
/**
* 按学号查询学生
*
* @param $id
* @return null|Student
*/
function findStudentById($id)
{
// 获得数据库连接
$conn = getConn();
// 定义SQL字符串
$sql = "SELECT * FROM student WHERE id = $id";
// 执行查询,返回结果集
$result = $conn->query($sql);
echo "<table border='1'>
<tr>
<th>id</th>
<th>name</th>
<th>code</th>
<th>coursecode</th>
<th>instructor</th>
<th>ta'sname</th>
<th>ta'semail</th>
<th>ta'sphone</th>
<th>A</th>
<th>B</th>
<th>C</th>
<th>score</th>
<th>D</th>
<th>E</th>
<th>level</th>
<th>comment</th>
</tr>";
// 将查询结果放进关联数组
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['ccode'] . "</td>";
echo "<td>" . $row['cname'] . "</td>";
echo "<td>" . $row['instructor'] . "</td>";
echo "<td>" . $row['taname'] . "</td>";
echo "<td>" . $row['taemail'] . "</td>";
echo "<td>" . $row['taephone'] . "</td>";
echo "<td>" . $row['A'] . "</td>";
echo "<td>" . $row['B'] . "</td>";
echo "<td>" . $row['C'] . "</td>";
echo "<td>" . $row['score'] . "</td>";
echo "<td>" . $row['D'] . "</td>";
echo "<td>" . $row['E'] . "</td>";
echo "<td>" . $row['level'] . "</td>";
echo "<td>" . $row['com'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
/**
* 添加学生记录
* @param $student
* @return bool|mysqli_result
*/
function insertStudent($student)
{
$id = $student->getId();
$name = $student->getName();
$ccode= $student->getCCode();
$cname = $student->getcname();
$instructor = $student->getinstructor();
$taname = $student->gettaname();
$taemail = $student->gettaemail();
$taephone = $student->getTelephone();
$A = $student->getA();
$B = $student->getB();
$C= $student->getC();
$score = $student->getscore();
$D = $student->getD();
$E = $student->getE();
$level = $student->getlevel();
$com = $student->getcom();
// 获得数据库连接
$conn = getConn();
// 定义SQL字符串
$sql = "INSERT INTO student VALUES ('$id', '$name', '$ccode', '$cname', '$instructor','$taname','$taemail','$taephone','$A','$B','$C','$score','$D','$E','$level','$com')";
// 执行插入操作
$retval = $conn->query($sql);
return $retval;
}
/**
* 按学号删除学生
*
* @param $id
*/
function deleteStudentById($id) {
// 获得数据库连接
$conn = getConn();
// 定义SQL字符串
$sql = "DELETE FROM student WHERE id = $id";
// 执行删除操作
$retval = $conn->query($sql);
return $retval;
}
?>
student.php
<?php
class Student
{
private $id;
private $name;
private $ccode;
private $cname;
private $instructor;
private $taname;
private $taemail;
private $taphone;
private $A;
private $B;
private $C;
private $score;
private $D;
private $E;
private $level;
private $com;
/**
* @return mixed
*/
public function getId()
{
return $this->id;
}
/**
* @param mixed $id
*/
public function setId($id)
{
$this->id = $id;
}
/**
* @return mixed
*/
public function getName()
{
return $this->name;
}
/**
* @param mixed $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return mixed
*/
public function getCCode()
{
return $this->ccode;
}
/**
* @param mixed $ccode
*/
public function setCCode($ccode)
{
$this->ccode = $ccode;
}
/**
* @return mixed
*/
public function getcname()
{
return $this->cname;
}
/**
* @param mixed $cname
*/
public function setcname($cname)
{
$this->cname = $cname;
}
/**
* @return mixed
*/
public function getinstructor()
{
return $this->instructor;
}
/**
* @param mixed $instructor
*/
public function setinstructor($instructor)
{
$this->instructor = $instructor;
}
/**
* @return mixed
*/
public function gettaname()
{
return $this->taname;
}
/**
* @param mixed $taname
*/
public function settaname($taname)
{
$this->taname = $taname;
}
/**
* @return mixed
*/
public function gettaemail()
{
return $this->taemail;
}
/**
* @param mixed $taemail
*/
public function settaemail($taemail)
{
$this->taemail = $taemail;
}
/**
* @return mixed
*/
public function getTelephone()
{
return $this->taphone;
}
/**
* @param mixed $taphone
*/
public function setTelephone($taphone)
{
$this->taphone = $taphone;
}
/**
* @return mixed
*/
public function getA()
{
return $this->A;
}
/**
* @param mixed $A
*/
public function setA($A)
{
$this->A = $A;
}
/**
* @return mixed
*/
public function getB()
{
return $this->B;
}
/**
* @param mixed $B
*/
public function setB($B)
{
$this->B = $B;
}
/**
* @return mixed
*/
public function getC()
{
return $this->C;
}
/**
* @param mixed $C
*/
public function setC($C)
{
$this->C = $C;
}
/**
* @return mixed
*/
public function getscore()
{
return $this->score;
}
/**
* @param mixed $score
*/
public function setscore($score)
{
$this->score = $score;
}
/**
* @return mixed
*/
public function getD()
{
return $this->D;
}
/**
* @param mixed $D
*/
public function setD($D)
{
$this->D = $D;
}
/**
* @return mixed
*/
public function getE()
{
return $this->E;
}
/**
* @param mixed $E
*/
public function setE($E)
{
$this->E = $E;
}
/**
* @return mixed
*/
public function getlevel()
{
return $this->level;
}
/**
* @param mixed $level
*/
public function setlevel($level)
{
$this->level = $level;
}
/**
* @return mixed
*/
public function getcom()
{
return $this->com;
}
/**
* @param mixed $com
*/
public function setcom($com)
{
$this->com = $com;
}
}
?>
学号查找学生 (user admin)
dofindstudent.php
<?php
require("StudentDao.php");
$id = $_POST['id'];
if ($id == null) {
echo "你要查询的学生不存在!";
} else {
echo findStudentById($id);
}
?>
findstudentbyID.php
<!DOCTYPE html>
<html lang="ch">
<head>
<meta charset="UTF-8">
<title>按学号查询学生</title>
<style>
html{
height: 100%;
}
body{
height: 100%;
font-family: 'JetBrains Mono Medium';
display: flex;
align-items: center;
justify-content: center;
background-color: black;
}
.form-wrapper{
width: 300px;
background-color: rgb(41,45,62);
color: #ffffff;
border-radius: 2px;
padding: 50px;
}
.form-wrapper .header{
text-align: center;
font-size: 35px;
text-transform: uppercase;
line-height: 100px;
}
.form-wrapper .action{
display: flex;
justify-content: center;
}
.form-wrapper .action .btn{
width: 60%;
text-transform: uppercase;
border: 2px solid #FFFFFF;
text-align: center;
line-height: 50px;
border-radius: 30px;
cursor: pointer;
transition:0.2s;
}
</style>
</head>
<body>
<div class="form-wrapper" align="center" >
<div class="header">
按学号查询学生
</div>
<div class="action">
<form action="doFindStudentById.php" method="post">
学生学号:<input type="number" name="id">
</div>
<div class="border-wrapper">
<input type="submit" value="查询"><br>
</div>
</div>
</form>
</body>
</html>
查看所有学生 增删操作(仅admin)
studentlist.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>学生列表</title>
</head>
<body>
<h3>学生列表</h3>
<?php
require("StudentDao.php");
@$retval = $_GET['retval'];
if ($retval) {
echo "<script type='text/javascript'>alert('记录删除成功!');</script>";
}
$students = findAllStudents();
if (count($students) > 0) {
echo "<table border='1' cellpadding='11' cellspacing='0'>";
echo "<tr><td>学生学号</td><td>学生姓名</td><td>课程号</td><td>课程名</td>"
."<td>讲师</td><td>助教</td><td>助教邮箱</td><td>助教电话</td>"
."<td>A:出勤率低</td><td>B:未参加期中考试</td><td>C:期中成绩低于平均分</td><td>期中成绩</td><td>D:多次未交作业</td>"
."<td>其他情况</td><td>关注级别</td><td>其他补充</td><td>操作</td></tr>";
foreach ($students as $student) {
$id = $student->getId();
$name = $student->getName();
$ccode= $student->getCCode();
$cname = $student->getcname();
$instructor = $student->getinstructor();
$taname = $student->gettaname();
$taemail = $student->gettaemail();
$taephone = $student->getTelephone();
$A = $student->getA();
$B = $student->getB();
$C= $student->getC();
$score = $student->getscore();
$D = $student->getD();
$E = $student->getE();
$level = $student->getlevel();
$com = $student->getCom();
echo "<tr><td>$id</td><td>$name</td><td>$ccode</td><td>$cname</td>"
."<td>$instructor</td><td>$taname</td><td>$taemail</td><td>$taephone</td>"
."<td>$A</td><td>$B</td><td>$C</td><td>$score</td><td>$D</td>"
."<td>$E</td><td>$level</td><td>$com</td>"
."<td><a href='DeleteStudentById.php?id=$id' οnclick='return deleteStudent();'>删除</a></td>
</tr>";
}
echo "</table>";
} else {
echo "学生表里没有记录!";
}
?>
<script type="text/javascript">
function deleteStudent() {
var choice = confirm("你是否要删除该记录?");
return choice;
}
</script>
</body>
</html>
deletstudent.php
<?php
require("StudentDao.php");
$id = $_GET['id'];
$retval = deleteStudentById($id);
$location="StudentList.php?retval=$retval";
header("location:$location");
?>