1、敲代码前的准备工作

1.1准备开发工具

1.1.1 开发工具的说明

本系统利用了xampp 集成环境,利用PHP写后端,html、css、js写前端(其实笔者也是现学现卖

1.1.2 xampp工具的下载

点击这里xampp下载
切记一定要安装在系统盘内,也就是C盘

1.1.3 建立项目文件

在安装完xampp之后,到其相关的安装目录下建立项目文件
路径如下:
如图所示在C:\xampp\htdocs下建立一个PHP_Project的项目文件
在这个目录下建立ExameSystem的文件夹, 用来存放代码文件。
里面的201.jpg是背景图 读者可根据自己的喜好寻找图片,但图片名不能变否则将会出现BUG.

1.2 项目的需求分析以及数据库的设计

1.2.1 需求模块划分

2.1)教师出题模块
由于本系统只有一个管理账号,所以对于教师出只能是一对多的,即一个老师能够出多个题库,一个题库只能由一个老师来出。老师可以对题库中的所有题目进行修改和删除,可以查看题库中所有的题目。
2.2)学生考试模块
由于在本系统中,学生属于普通用户,所以可以注册多个学生账号。学生可以做多个题目,一个题目也可以有多个学生做。同时一个学生可以进行多场考试,但是每场考试的信息将被记录下来,并且入库。因此,学生可以查看自己的历史考试记录。
2.3)用户管理模块
本系统提供了用户账号及密码管理模块,学生可以进行注册、登录、以及修改密码。但是只能注册普通学生账号。同时,不同的用户有不同的权限,登录之后只能访问不同的界面。

1.2.2 数据库的数据表的设计

1、用户信息表)

字段中文名 字段英文名 类型 长度 说明
用户编号 Id Int 6 为主键
用户名 Name varchar 12
用户密码 Pass varchar 12
是否为教师 Admin Int 1 为bool变量

2、题库题目表)

字段中文名 字段英文名 类型 长度 说明
题目编号 Id Int 6 为主键
题目内容 Content Varchar 200
题目类型 Type Int 1 1为选择题2为判断题
题目答案 Answer Int 1 为判断题的答案1为正确0为错误

3、选择题答案表)

字段中文名 字段英文名 类型 长度 说明
答案编号 Id Int 6 为主键
答案内容 Content Varchar 200 选项内容
答案所属的问题编号 Question Int 1
答案是否被选 answer Int 1 1表示被选,0表示不被选

3、考试记录表)

字段中文名 字段英文名 类型 长度 说明
记录编号 Id Int 6 为主键
用户名 Name Varchar 12
用户考试成绩 Score Int 5
用户考试时间 date varchar 20

2、功能模块的的实现


前面讲了那么多的,终于到了敲代码的阶段,是不是很开心呢!
下面就是见证奇迹的时刻

2.1 用户管理模块的实现

2.1.1 安装模块(install)

配置文件 config.php(后面经常用)

<?php
$host_name="localhost";# IP名
$host_user="root"; # 自己数据库的登录名
$host_pass="root"; # 自己数据库的密码
$db_name="test"; # 之前建立要用的数据库名
$test_user="test_user"; # 库中的表名
$test_question="test_question";
$test_answer="test_answer";
$test_exam="test_exam";
$mysqli=new mysqli($host_name,$host_user,$host_pass,$db_name);
?>

install_l.php

<center><table border=1><form action="install.php" method="post"><tr><td colspan="2" align="center">输入管理员信息</td></tr><tr><td>输入管理员名称:</td><td><input type="text" name="user"></td></tr><tr><td>输入管理员密码:</td><td><input type="password" name="pass"></td></tr><tr><td colspan="2" align="center"><input type="submit" value="开始安装"></td></tr></form></table></center>

install.php

<?php
//$isset=$_POST["user"]
if(!($isset1=$_POST["user"] and $issert2=$_POST["pass"]))  //有个Notice
{echo "您输入的的管理员账号或密码为空 !<p>";echo "单击<a href='install_l.php'>这里</a>重新安装";
}
else
{include"config.php";$sql0="create database test use test";$step0=$mysqli->query($sql0) or die ($mysqli->error);$sql1="create table $test_user(id int(6) not null auto_increment primary key,name varchar(12) not null default ' ',pass varchar(12) not null default ' ',admin int(1) not null default 0)ENGINE=InnoDB";$step1=$mysqli->query($sql1) or die($mysqli->error);$sql2="create table $test_question(id int(6) not null auto_increment primary key,content varchar(200) not null default ' ',type int(1) not null default 0,answer int(1) not null default 0)ENGINE=InnoDB";$step2=$mysqli->query($sql2) or die($mysqli->error);$sql3="create table $test_answer(id int(6) not null auto_increment primary key,content varchar(200) not null default ' ',question int(5) not null default 0,answer int(1) not null default 0)ENGINE=InnoDB";$step3=$mysqli->query($sql3) or die($mysqli->error);$sql4="create table $test_exam(id  int(6) not null auto_increment primary key,name varchar(12) not null default ' ',sorce int(5) not null default 0,date varchar(20) not null default 0)ENGINE=InnoDB";$step4=$mysqli->query($sql4) or die($mysqli->error);$user=$_POST["user"];$pass=$_POST["pass"];$sql5="insert into $test_user (name,pass,admin) values ('$user','$pass',1)";$step5=$mysqli->query($sql5) or die($mysqli->error);if($step0 and $step1 and $step2 and $step3 and $step4 and $ste5){echo "安装成功<p>";echo "管理员名为:$user";echo "单击 <a href='index.php'>这里</a>进入系统";}else{echo "建表不成功";}
}
?>
</center>

创建主页index.php

<?php
echo "<center>";
echo "欢迎使用智能考试系统!<p>";
if (null==($_COOKIE["user"] OR $_COOKIE["user"]==" "))
{echo "你还没有登录!<p>";echo "<a href='login_l.php'>登录</a> &nbsp;&nbsp;&nbsp;<a href='reg_l.php'>注册</a>";
}
else
{echo "欢迎您:".$_COOKIE["user"];echo "<p>";include "config.php";$sql="select admin from $test_user where name='$_COOKIE[user]'";$result=$mysqli->query($sql);$admin=$result->fetch_array();if ($admin[0]==0){echo "你是普通用户,点<a href='test.php'>这里</a>开始考试<p>";echo "点<a href='exam.php'> 这里</a>查看历史成绩";}else{echo "你是管理员用户,点<a href='admin.php'>这里</a>对题库进行修改";}echo "<p> 点<a href='edit_pass.php'>这里</a> 修改密码<p>";echo "<p> 点<a href='exit.php'>这里</a>退出登录<p>";
}
?>

2.1.2注册模块

reg_l.php

<!DOCTYPE html>
<html>
<head><title>注册</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;}   center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:30px;margin-top:20px;}#sub{width:120px;height:40px;text-algin:center;}</style>
</head>
<body>
<center>
<table>
<h2>用户注册</h2>
<form action="reg.php" method="post">
<input type="text" name="user" placeholder="输入用户名"><br/>
<input type="password" name="pass"placeholder="输入密码"><br/>
<input type="password" name="rpass"placeholder="再次输入密码"><br/>
<input id="sub"type="submit"  value="注册"><br/>
</form>
已有密码单击<a href="login_l.php"><b><big>登录</big></b></a>进行登录
</table>
</center>
</body>
</html>

reg.php

<?php
$isset1=$_POST["user"];
$isset2=$_POST["pass"];
$isset3=$_POST["rpass"];
if(!($isset1 and $isset2 and $isset3))  //有个Notice
{  echo "<center>";echo "您没有输入用户名或者密码、确认密码!\n";echo "单击<a href='reg_l.php'>这里</a>重新注册";echo "</center>";
}
else if($isset2!=$isset3)
{echo "<center>";echo "您输的密码不一致!\n";echo "单击<a href='reg_l.php'>这里</a>重新注册";echo "</center>";
}
else
{include "config.php";$user=$_POST["user"];$pass=$_POST["pass"];$sql="select * from $test_user where name='$user'";$result=$mysqli->query($sql);$num=$result->num_rows;if($num>0){echo "用户名已存在!<p>";echo "单击<a href='reg_l.php'>这里</a>重新注册";}else{$sql="insert into $test_user (name,pass,admin) values ('$user','$pass',0)";$result=$mysqli->query($sql) or die($mysqli->error);if($result){echo "<center>";echo "注册成功!<p>";echo "单击 <a href='login_l.php'>这里</a>登录系统";echo "</center>";}}
}
?>

2.1.3 登录模块

login_l.php

<!DOCTYPE html>
<html>
<head><title>登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;}   center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}#sub{width:120px;height:40px;text-algin:center;}</style>
</head>
<body><center><table><h2>用户登录</h2><form action="login.php" method="post"><input type="text" name="user" placeholder="输入用户名"><br/><input type="password" name="pass"placeholder="输入密码"><br/><input id="sub"type="submit" value="登录"></form></table></center>
</body>
</html>

login.php

<?php
$isset1=$_POST["user"];
$isset2=$_POST["pass"];
if (!($isset1 and $isset2))
{echo "你输入的登录账号或密码为空!<p>";echo "单击<a href='login_l.php'>这里</a>重新登录";
}
else
{include "config.php";$user=$_POST["user"];$pass=$_POST["pass"];$sql="select * from $test_user where name='$user' and pass='$pass'";$result=$mysqli->query($sql);$num=$result->num_rows;if ($num==0){echo "<center>";echo "用户名或密码错误!<p>";echo "单击<a href='login_l.php'>这里</a>重新登录";echo "</center>";}else{setcookie("user",$user);echo "<center>";echo "登录成功!<p>";echo "单击<a href='index.php'>这里</a>进入系统";echo "</center>";}
}?>

2.1.4 修改密码模块edit_pass.php

<!DOCTYPE html>
<html>
<head><title>修改密码</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;} center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}</style>
</head>
<body>
<?php
echo  "<center>";
echo "<h1>欢迎使用智能考试系统!</h1><p>";
if (null==($_COOKIE["user"] OR $_COOKIE["user"]==" "))
{echo "你还没有登录!<p>";echo "<a href='login_l.php'>登录</a> &nbsp;&nbsp;&nbsp;<a href='reg_l.php'>注册</a>";
}
else
{if(null==$_POST["pass"]){?>
<table>
<form action ="edit_pass.php" method="post">
<h2 align="center">修改密码</h2>
<tr>
<td>用户名:</td>
<td><?php echo $_COOKIE["user"]?></td>
</tr>
<tr>
<td>输入旧密码:</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td>输入新密码:</td>
<td><input type="password" name="new_pass"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="确认修改"></td>
</tr>
</form>
</table>
<a href="index.php"><big><b>返回</b></big></a>
<?php}else{$user=$_COOKIE["user"];$pass=$_POST["pass"];$new_pass=$_POST["new_pass"];include "config.php";$sql="select count(id) from $test_user where name='$user' and pass='$pass'";$result=$mysqli->query($sql) or die($mysqli->error);$num=$result->num_rows;if($num==0){echo "用户名或密码错误!";echo "单击<a href='edit_pass.php'>这里</a>重新输入";}else{$sql="update $test_user set pass='$new_pass' where name=$user and pass='$pass'";$result=$mysqli->query($sql) or die($mysqli->error);if($result){echo "<big><b>密码修改成功!</b></big>";echo "<p><a href='index.php'><b><big>返回</big></b></a>";}else{echo "密码修改出错";echo "<p>单击<a href='edit_pass.php'>这里</a>重新修改密码";}}}
}
?>
</body>
</html>

返回主页的exit.php

<?php
setcookie("user");
echo "<center>";
echo "成功退出登录<p>";
echo "单击<a href=index.php>这里</a>返回";
echo  "</center>";
?>

用户管理的模块就到此为止了,
接下来我们来实现教师出题的模块。

2.2教师模块的实现

2.2.1 教师身份验证 check_admin.php

<?php
include"config.php";
$sql="select COUNT(admin) from $test_user where name='$_COOKIE[user]'";
$result=$mysqli->query($sql);
$admin=$result->fetch_row();
if($admin[0]==0)
{echo "你不是管理员,不能执行该操作!";exit(" ");
}
?>

2.2.2 教师的登录后的界面admin.php

<!DOCTYPE html>
<html>
<head><title>登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;}   center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}#sub{width:120px;height:40px;text-algin:center;}</style>
</head>
<body>
<?php
echo "<center>";
include "check_admin.php";
echo "题库管理";
echo "<a href='add_question.php'>添加题库</a><p>";
include "config.php";
$sql="select *from $test_question";
$result=$mysqli->query($sql);
$num=$result->num_rows;
if($num==0)
{echo "还没有题库记录";
}
else
{echo "共有".$num."条题目记录";echo "<p>";echo "<table border='1'>";echo "<tr><td>序号</td><td>题目</td><td>类型</td><td>查看</td><td>修改</td><td>删除</td></tr>";while ($row=$result->fetch_array()){echo "<tr>";echo "<td>".$row["id"]."</td>";echo "<td>".$row["content"]."</td>";echo "<td>";if($row["type"]==1) echo "选择题";else echo "判断题";echo "</td>";echo "<td> <a href=show_question.php?id=".$row[0].">查看</a></td>";echo  "<td> <a href=edit_question.php?id=".$row[0].">修改</a></td>";echo  "<td> <a href=del_question.php?id=".$row[0].">删除</a></td>";echo "</tr>";}echo "</table>";
}echo "<p>单击<a href='index.php'>这里</a>返回";
echo "</center>";
?>
</body>
</html>

2.2.3 对题库进行“常规”操作

添加问题模块add_question.php

<!DOCTYPE html>
<html>
<head><title>添加题目</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;} center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}#sub{width:120px;height:40px;text-algin:center;}</style>
</head>
<body>
<?php
echo "<center>";
include "check_admin.php";
if (null==$_POST["type"])
{?>
<table border="1">
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post">
<tr> <td colspan="2" align="center">请选择题目类型</td></tr>
<tr>
<td>题目类型</td>
<td>
<select size="1" name="type">
<option value="1"> 选择题</option>
<option value="2"> 判断题</option>
</select>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="下一步">
</td>
</tr>
</form>
</table>
<p>单击<a href=admin.php>这里</a>返回</p>
<?php
}
else
if(null==$_POST["content"])
{?>
<table border="1">
<form action="<?php echo $_SERVER["PHP_SELF"]?>" method="post">
<tr>
<td>题目类型: </td>
<td><?php
if($_POST["type"]==1)echo "选择题";
else echo "判断题";
?>
</td></tr>
<tr>
<td>请输入题目内容</td>
<td><input type="text" name="content" required='required' size="30"></td>
<tr>
<tr>
<td>请输入/选择该题答案</td>
<td>
<?php
if($_POST["type"]==1)
{for($i=0;$i<4;$i++){echo chr($i+65).".<input type=text name='answer[]' required='required'>\n";echo "<input type=radio name='check' value=".$i."><br>\n";}
}
else
{echo "<input type=radio value=1 name='answer'>正确\n";echo "<input type=radio value=2 name='answer'>错误\n<p>";
}
echo "被选中项为正确答案";
?>
</td>
<tr></tr>
<td colspan="2" align="center">
<input type="hidden" name="type" value="<?php echo $_POST["type"]?>">
<input type="button" value="上一步"; onclick="history.go(-1)"><input
type="submit" value="下一步">
</td>
</tr>
</form>
</table>
<?php
}
else
{$type=$_POST["type"];
$content=$_POST["content"];
$answer=$_POST["answer"];
include "config.php";
if($type==2)  //判断题的入库
{$sql="INSERT  INTO  $test_question(content,type,answer)VALUES('$content','$type','$answer')";$result=$mysqli->query($sql) or die($mysqli->error);if($result){echo "成功添加题库";echo "单击<a href=admin.php>这里</a>返回";}else{echo "添加题库出错";echo "<p>单击<a href='add_question.php'>这里</a>重新添加";}
}
else   //选择题入库
{$check=$_POST["check"];$sql="INSERT  INTO  $test_question (content,type)VALUES ('$content','$type')";$result=$mysqli->query($sql) or die($mysqli->error);$question_id=$mysqli->insert_id;$sql2="INSERT INTO $test_answer(content,question,answer) values";for($i=0;$i<4;$i++){$sql2=$sql2."(";$sql2=$sql2."'".$answer[$i]."',";$sql2=$sql2.$question_id.",";if($check==$i) $sql2=$sql2."1)";else $sql2=$sql2."0)";if($i<3) $sql2=$sql2.",";}$result2=$mysqli->query($sql2) or die($mysqli->error);if($result and $result2){echo "成功添加题库";echo "单击<a href=admin.php>这里</a>返回";}else {echo "添加题库出错";echo "<p>单击<a href='add_question.php'>这里</a>重新添加";}
}
}echo "</center>";
?>
</body>
</html>

查看题目的模块show_question.php

<!DOCTYPE html>
<html>
<head><title>登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;}   center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}</style>
</head>
<body>
<center>
<?php
include "check_admin.php";
include "config.php";
$sql="select *from $test_question where id='$_GET[id]'";
$result=$mysqli->query($sql);
$row=$result->fetch_array();
echo "<table border='1'>";
echo "<tr><td>题目类型:</td><td>";
if ($row["type"]==1) echo "选择题";
else echo "判断题";
echo "</td></tr>";
echo "<tr><td>题目内容</td><td>";
echo $row["content"];
echo "</td></tr>";
echo "<tr><td>题目答案</td><td>";
if($row["type"]==1)  //选择题
{$sql2="select * from $test_answer where question='$_GET[id]'";$result2=$mysqli->query($sql2);while ($row2=$result2->fetch_array()){echo $row2["content"];if ($row2["answer"]==1) echo "  正确";echo "<br>";}
}
else //判断题
{if($row2["answer"]==1) echo " 正确";else echo " 错误";
}
echo "</td></tr>";
echo "</table>";
echo "<p><a href=admin.php>返回</a>";
?>
</center>
</body>
</html>

修改题库操作edit_question.php

<!DOCTYPE html>
<html>
<head><title>修改题目</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;} center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}</style>
</head>
<body>
<center>
<?php
include "check_admin.php";
if (!isset($_POST["content"]))
{include "config.php";$sql="select * from $test_question where id='$_GET[id]'";$result=$mysqli->query($sql);$row=$result->fetch_array();echo "<table border='1'>\n";echo "<form action='".$_SERVER["PHP_SELF"]."'method='post'>\n";echo "<tr><td>题目类型</td><td>\n";if ($row["type"]==1) echo "选择题";else echo "判断题";echo "</td></tr>";echo "<tr><td>题目内容</td><td>";echo "<input type='text' name='content' value='".$row["content"]."' size='30' required='required'>";echo "</td></tr>\n";echo "<tr><td>题目答案</td><td>";if($row["type"]==1)//修改选择题答案{$sql2="select * from $test_answer where question='$_GET[id]'";$result2=$mysqli->query($sql2);while($row2=$result2->fetch_array()){echo "<input type ='text' name='answer[]' value='".$row2["content"]."'required='required'>\n";echo "<input type ='hidden' name ='answer_id[]' value='".$row2["id"]."'>\n";echo "<input type=radio name='check' value=".$row2["id"];if($row2["answer"]==1) echo "checked ";echo ">\n";echo "<br>\n";}}else{echo "<input type=radio value=1 name='answer'";if($row["answer"]==1) echo "checked";echo ">正确\n";echo "<input type=radio value=0 name='answer'";if($row["answer"]==2) echo "checked";echo ">错误\n"; }echo "<input type=hidden name='id' value='".$row["id"]."'>\n";echo "<input type=hidden name='type' value='".$row["type"]."'>\n";echo "</td></tr>\n";echo "<tr><td colspan='2' align='center'><input type='submit' value='确认修改'></td></tr>\n";echo "</form>\n";echo "</table>\n";echo "<p> <a href=admin.php>返回</a>\n";
}
else
{$id=$_POST["id"];$content=$_POST["content"];$type=$_POST["type"];$answer=$_POST["answer"];include "config.php";if($type==1) //如果是选择题,修改题目和选项{$check=$_POST["check"];$answer_id=$_POST["answer_id"];$sql="UPDATE $test_question set content='$content' where id='$id'";$result=$mysqli->query($sql) or die($mysqli->error);for ($i=0;$i<4;$i+=1){$s="update $test_answer set content='$answer[$i]'";if ($check==$answer_id["$i"]){$s=$s.",answer=1";}else{$s=$s.",answer=0";}$s=$s." where id=$answer_id[$i]";$result=$mysqli->query($s) or die ($mysqli->error);}if($result){echo "<p> 成功修改题库<p>";echo "单击<a href=admin.php>这里</a>返回";}else echo "修改出错!";}else {$sql="UPDATE $test_question set content='$content',answer='$answer' where id='$id'";$result=$mysqli->query($sql) or die($mysqli->error);if($result){echo "<p> 成功修改题库<p>";echo "单击<a href=admin.php>这里</a>返回";}else echo "修改出错!";}
}
?>
</body>
</html>

The last one (删库跑路)del_question.php

<!DOCTYPE html>
<html>
<head><title>登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;}   center{padding-top:60px;}      input{width:200px;height:40px;font-size:20px;padding-left:10px;margin-top:20px;}</style>
</head>
<body>
<center>
<?php
include "check_admin.php";
if(!isset($_POST["id"]))
{include "config.php";$sql="select * from $test_question where id='$_GET[id]'";$result=$mysqli->query($sql);$row=$result->fetch_array();echo "<table border='1'>\n";echo "<form action='".$_SERVER["PHP_SELF"]."'method='post'>\n";echo "<tr><td> 题目内容</td><td>";echo $row["content"];echo "</td></tr>\n";echo "<input type=hidden name='id' value='".$row["id"]."'>\n";echo "<input type=hidden name='type' value='".$row["type"]."'>\n";echo "<tr><td colspan='2' align='center'><input type='submit' value='确认删除'></td></tr>\n";echo "</form>\n";echo "</table>\n";echo "<p> <a href=admin.php>返回</a>\n";
}
else
{include "config.php";$id=$_POST["id"];$type=$_POST["type"];$sql="delete  from $test_question where id='$id'";$result=$mysqli->query($sql) or die($mysqli->error);if ($type==1){$sql="delete  from $test_answer where question='$id'";$result=$mysqli->query($sql) or die($mysqli->error);}if($result){echo "<p>成功删除题库";echo "单击<a href=admin.php>这里</a>返回";}else echo "删除题库出错";}
?>
</center>
</body>
</html>

教师模块完了,接下来‘’砸门” 实现最好一个模块,
学生考试模块

2.3学生考试模块

2.3.1 进行考试 test.php

<?php
echo "<center>";
echo "欢迎使用智能考试系统!<p>";
if (null==($_COOKIE["user"] OR $_COOKIE["user"]==" "))
{echo "你还没有登录!<p>";echo "<a href='login_l.php'>登录</a> &nbsp;&nbsp;&nbsp;<a href='reg_l.php'>注册</a>";
}
else
{if(null==$_POST["c"])//如果没有提交则显示表单{echo "欢迎您".$_COOKIE["user"];echo "<p> 现在开始考试<p>\n";echo "</center>";include "config.php";echo "<form action='".$_SERVER["PHP_SELF"]."'method='post'>\n";echo "一、选择题(每题1分)<p>\n";$sql="select * from $test_question where type=1 order by rand() LIMIT 5";$result=$mysqli->query($sql) or die($mysqli->error);$i=1;while ($row=$result->fetch_array())//显示选择题{echo $i."、";echo $row["content"];//显示题内容echo "<br>\n";$s="select *from $test_answer where question='$row[id]'";$r=$mysqli->query($s) or  die($mysqli->error);$head=65;while ($row2=$r->fetch_array())//显示选项内容{ echo "<input type='radio' name=c[".($i-1)."] value=".$row2["id"].">";echo chr($head).".";echo $row2["content"]."\n";echo "<br>\n";$head+=1;}$i+=1;echo "<p>\n";}echo "二、判断题(每题1分)<P>\n";$sql="select * from $test_question where type=2 order by rand() LIMIT 5";$result=$mysqli->query($sql) or die($mysqli->error);$i=1;while ($row=$result->fetch_array())//显示判断题{echo $i."、";echo $row["content"];echo "<br>\n";echo "<input type='radio' name=d[".($i-1)."] value ='1'>正确\n";echo "<input type='radio' name=d[".($i-1)."] value ='2'>错误\n";echo "<input type='hidden' name=s[] value =".$row["id"].">\n";$i+=1;echo "<p>\n";}echo "<p> <input type='submit' value='完成考试'>";echo "</form>";}else{$c=$_POST["c"]; //学生选择题的答案$d=$_POST["d"]; //学生判断题的答案$s=$_POST["s"]; //判断题的题号$score=0;$num1=count($c);$num2=count($d);//echo $num1."<p>";include "config.php";for ($j=0;$j<$num1;$j+=1)  //给学生的选择题打分{$sql="select answer from $test_answer where id='$c[$j]'";$result=$mysqli->query($sql)or die($mysqli->error);$a=$result->fetch_row();if($a[0]==1) $score+=1;}for($k=0;$k<$num2;$k+=1){$sql="select id from $test_question where id='$s[$k]' and answer='$d[$k]'";$result=$mysqli->query($sql) or die($mysqli->error);$num=$result->num_rows;if($num>0) $score+=1;}$date=date('Y-m-d H:i:s');echo "你的得分为:".$score;$sql="insert into $test_exam (name, score,date) values ('$_COOKIE[user]','$score','$date')";$result=$mysqli->query($sql)or die($mysqli->error);if ($result){echo "<center>";echo "<p>已将此次成绩入库<p>";echo "单击<a href=index.php>这里</a>返回";echo "</center>";}else{echo "<p>成绩入库不成功<p>";echo "单击<a href=index.php>这里</a>返回";}}
}
?>

2.3.2 查询历史成绩单exam.php

<!DOCTYPE html>
<html>
<head><title>登录</title><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><style type="text/css">body center{width:1366px;height:768px;background:url(201.jpg);background-size:100% 100%;margin:0 auto;}   center{padding-top:60px;}      </style>
</head>
<body>
<?php
echo  "<center>";
echo "欢迎使用智能考试系统!<p>";
if (null==($_COOKIE["user"] OR $_COOKIE["user"]==" "))
{echo "你还没有登录!<p>";echo "<a href='login_l.php'>登录</a> &nbsp;&nbsp;&nbsp;<a href='reg_l.php'>注册</a>";
}
else
{$user=$_COOKIE["user"];echo "查看用户".$user."的历史考试成绩<p>";include "config.php";$sql="select *from $test_exam where name='$user'";$result=$mysqli->query($sql) or die ($mysqli->error);if(($num=$result->num_rows)==0){echo "还没有用户的考试记录";}else{echo "共有".$num."条历史考试记录";echo "<p>";echo "<table>";echo "<tr><td>序号</td><td>用户</td><td>成绩</td><td>考试日期</td></tr>";while( $row=$result->fetch_array()){echo "<tr>";echo "<td>".$row["id"]."</td>";echo "<td>".$row["name"]."</td>";echo "<td>".$row["score"]."</td>";echo "<td>".$row["date"]."</td>";echo "</tr>";}echo "</table>";}echo "<a href=index.php><big><b>返回</big></b></a>";echo "</center>";
}
?>
</body>
</html>

终于完了,妈呀!累死宝宝了

3 效果展示

3.1启动xampp中的Apache服务器

双击xampp-control.exe文件

双击Apache所对的Starten按钮, 效果如下:

3.2 打开浏览器

***输入http://localhost/PHP_Project/ExamSystem/install_l.php***如下网址进行安装


安装完成后, 就能运行了。
登入界面如下

用管理员账户登入后效果如下:

其余的功能留给读者体会

4、系统的不足

由于笔者也是在前端没学,后端现学的基础上做的“数据库课程设计”,所以系统粗制滥造,但是笔者也付出一定的时间和精力。
所以不喜勿喷

数据库课程设计————学生考试系统相关推荐

  1. oracle学生考勤,Oracle数据库课程设计――学生考勤系统的Oracle实现1

    Oracle数据库课程设计――学生考勤系统的Oracle实现1 辽宁工程技术大学 Oracle数据库课程设计报告 学生考勤系统 姓 名: XXXXX 班 级: 计SJ08-1班 学 号: 完成日期: ...

  2. 查询学生选修课程管理系统java_JAVA数据库课程设计学生选课管理系统的

    <JAVA数据库课程设计学生选课管理系统的>由会员分享,可在线阅读,更多相关<JAVA数据库课程设计学生选课管理系统的(59页珍藏版)>请在人人文库网上搜索. 1.一.课程设计 ...

  3. 数据库课程设计——学生宿舍信息管理系统

    数据库课程设计--学生宿舍信息管理系统 目录 1.设计目的... 2 2.任务与要求... 2 3.学生宿舍管理系统课程设计... 2 3.1 引言... 2 3.2需求分析... 2 3.2.1. ...

  4. java学生选课系统课程设计报告_Java语言程序设计课程设计-学生选课系统

    <Java语言程序设计课程设计-学生选课系统>由会员分享,可在线阅读,更多相关<Java语言程序设计课程设计-学生选课系统(23页珍藏版)>请在人人文库网上搜索. 1.10届 ...

  5. oracle学生信息管理系统课程设计,数据库课程设计-学生信息管理系统的设计与实现.doc...

    数据库课程设计-学生信息管理系统的设计与实现 2011-2012课程设计II 学生信息管理系统的设计与实现 一 设计内容 建立一个简单的在校学生信息查询系统,可以让使用者查询到学生的一些简单的个人信息 ...

  6. 签到考勤java课设_Java程序设计课程设计学生考勤系统Word版

    <Java程序设计课程设计学生考勤系统Word版>由会员分享,可在线阅读,更多相关<Java程序设计课程设计学生考勤系统Word版(6页珍藏版)>请在人人文库网上搜索. 1.传 ...

  7. 考勤管理系统c语言,C语言课程设计学生考勤系统最终版(范文1)

    <C语言课程设计学生考勤系统.doc>由会员分享,可免费在线阅读全文,更多与<C语言课程设计学生考勤系统(最终版)>相关文档资源请在帮帮文库(www.woc88.com)数亿文 ...

  8. c语言写考勤系统,C语言课程设计学生考勤系统

    <C语言课程设计学生考勤系统.doc>由会员分享,可免费在线阅读全文,更多与<C语言课程设计学生考勤系统>相关文档资源请在帮帮文库(www.woc88.com)数亿文档库存里搜 ...

  9. c语言程序设计学生考勤系统,C语言课程设计学生考勤系统最终版(样例3)

    <C语言课程设计学生考勤系统.doc>由会员分享,可免费在线阅读全文,更多与<C语言课程设计学生考勤系统(最终版)>相关文档资源请在帮帮文库(www.woc88.com)数亿文 ...

最新文章

  1. 服务器Jmail配置问题
  2. 节省大量教科书的三种潜在风险方法
  3. JBoss 4.2.x Spring 3 JPA Hibernate教程第2部分
  4. hdu 1874(Dijkstra + Floyd)
  5. link url下载php,php脚本生成google play url的下载链接,下载apk并自动反编译后获取android版本号...
  6. 怎么才能在APP里实现移动端车牌识别功能?
  7. 计算机应用基础离线考核,东师2016年秋季《计算机应用基础》期末考核离线作业...
  8. Redis-数据结构06-快速链表(quicklist)
  9. JavaScript学习(七十二)—严格模式
  10. Linux 命令(50)—— date 命令
  11. adobe animate2022动画制作软件
  12. ESP8266模块搭建最小系统原理图
  13. java fit 16s,16s分析之差异OTU 挑选(edgeR)
  14. JS自动播放视频脚本
  15. 共探人工智能新发展,AICON 2022即将重磅开启
  16. 加解密篇 - 什么是加密加盐 (分析web3j的加盐处理)
  17. oracle 10g express linux,使用Oracle10g express 版本方案介绍
  18. Matlab各历史版本
  19. 【学习笔记】汇编:关于CMP的使用实例
  20. JQuery 操作弹出层 iframe页面元素的方式

热门文章

  1. Vue实现微信分享好友,分享朋友圈。
  2. 怎样可以把excel表格转换成word文档
  3. Tushare 注册、更新与数据获取
  4. 带你玩转Visual Studio——单元测试
  5. 华为综合实验:VLAN技术与NAT技术
  6. 程序员的好,失去以后才懂的,这么好的男人你心动吗?
  7. 汇编——实现冒泡排序+讲解
  8. 职业高中计算机学科总结,高中信息技术工作总结精选 .doc
  9. 基于深度学习的高精度塑料瓶检测识别系统(PyTorch+Pyside6+YOLOv5模型)
  10. 抓包分析rtsp\rtp\h264