数据库课程设计————学生考试系统

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、用户信息表)

字段中文名字段英文名类型长度说明
用户编号IdInt6为主键
用户名Namevarchar12
用户密码Passvarchar12
是否为教师AdminInt1为bool变量

2、题库题目表)

字段中文名字段英文名类型长度说明
题目编号IdInt6为主键
题目内容ContentVarchar200
题目类型TypeInt11为选择题2为判断题
题目答案AnswerInt1为判断题的答案1为正确0为错误

3、选择题答案表)

字段中文名字段英文名类型长度说明
答案编号IdInt6为主键
答案内容ContentVarchar200选项内容
答案所属的问题编号QuestionInt1
答案是否被选answerInt11表示被选,0表示不被选

3、考试记录表)

字段中文名字段英文名类型长度说明
记录编号IdInt6为主键
用户名NameVarchar12
用户考试成绩ScoreInt5
用户考试时间datevarchar20

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、系统的不足

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值