基于PHP和mysql的简单学生成绩管理系统

本系统主要架构图如上图所示。PS:register_check.php的自动注册代码写在check.php里了。

使用数据库的两张表,user_info用户信息表和stu_info学生成绩信息表。



提供登录服务:分为管理员登录和学生登录,若登录时输入数据库中没有的账号 和密码的时候系统会自动注册,即将新账号信息写入user_info中去。

学生登录只可以进行查询操作,管理员登录可以进行增删和查操作,注册新账号的权限都是学生。

接下来上代码:

login.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>信息查询界面</title>
<style type = "text/css">
   	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/
</style>
</head>
<!--这是学生端的查询界面,不提供返回管理员页面的接口-->
<body>
<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">
	<p>请输入学生的学号进行查询操作</p>
	<p>如果要查询所有学生信息请输入“所有”进行查询</p>
</div>
<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
<form action="select_opt_stu.php" method="post" style="margin: 35px auto;padding:30px;box-shadow: 1px 1px 2px 1px #aaaaaa;border-radius: 3px;width:380px;">
	<input  type="text" name="check"  style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:240px;" placeholder="请输入要查询学生的学号">
	          
	<input type="submit" value="查询" style ="height : 36px;border:1px;background-color:#00bee7;color:#fff;width:72px;border-radius: 3px;">
</form>

</body>
	</html>

check.php

<title>验证账号密码后台程序</title>
<meta charset="utf-8">
    <?php
		function get_str($str){
			$val = ($_POST[$str])?$_POST[$str]:null;
			return $val;
		}
		$user = get_str("username");
		$pass = get_str("password");
		if($user==null or $pass == null){?>
			<script type="text/javascript">
				alert("用户名或密码为空,请重新输入");
				window.location.href="login.html";
			</script>
			<?php
		}
		$con = mysql_connect("localhost","root","root") or die("数据库链接失败");
		if(!$con){
	?>
	<script type = "text/javascript">
    	alert("连接服务器失败");
		window.location.href = "login.html";
    </script>
    <?php
		}
		$sel = mysql_select_db("SGMSystem",$con) or die("数据库选择失败");
		if(!$sel){
	?>
    <script type = "text/javascript">
		alert("选择数据库失败");
		window.location.href = "login.html";
	</script>
    <?php
		}
		$sql = "select * from user_info where username = '$user'";
		//echo $sql."<br>";
		$info = mysql_query($sql,$con);
		echo $info;
		$num = mysql_num_rows($info);
		if($num == null){
			//没有查找到,表示要注册
			$ins = "insert into user_info (username,password,is_manager) values('$user','$pass',0)";
			$info1 = mysql_query($ins,$con);
				//注册成功,返回登陆界面重新登录
				?>
				<script type="text/javascript">
					alert("注册成功,返回登陆界面重新登录");
					window.location.href="login.html";
				</script>
				<?php
		}	
		else{
			//登录成功
			$row = mysql_fetch_array($info);
			//echo $row['password'];
			}
			if($row['password']==$pass){
				if($row['is_manager'] == 1){
					//是管理员
	?>
    <script type = "text/javascript">
		alert("管理员登录成功");
		window.location.href = "welcome_mag.html";
	</script>
    <?php }?>
     <?php
	 if($row['is_manager'] != 1){
		 //普通用户登录
	 	//直接进入查询界面(学生端的查询界面不提供返回服务选择界面的接口)
	?>
     <script type = "text/javascript">
		alert("普通用户登录成功");
		window.location.href = "select_stu.html";
	</script>
	<?php }
		}
		else{
	?>
	<script type = "text/javascript">
		alert("密码错误");
		window.loaction.href = "login.html";
	</script>
	<?php
		}
		mysql_close($con);
	?>

welcom_mag.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>欢迎界面</title>
<style>
	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/

</style>
</head>
<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">欢迎管理员登录,您可以进行所有操作</div>
<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>

<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">请选择您需要的服务</div>
<div style="height:100px;width:240px;margin:0px auto;" align="center">
	<p><a href="insert.html" align="center" >输入学生成绩信息</a></p>
	<p><a href="select_mag.html" align="center">查询学生信息</a></p>
	<p><a href="delete.html" align="center">删除学生信息</a></p>
</div>
<body>
</body>
</html>

select_mag.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>信息查询界面</title>
<style type = "text/css">
   	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/
</style>
</head>

<body>
<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">
	<p>请输入学生的学号进行查询操作</p>
	<p>如果要查询所有学生信息请输入“所有”进行查询</p>
</div>
<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
<form action="select_opt.php" method="post" style="margin: 35px auto;padding:30px;box-shadow: 1px 1px 2px 1px #aaaaaa;border-radius: 3px;width:380px;">
	<input  type="text" name="check"  style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:240px;" placeholder="请输入要查询学生的学号">
	          
	<input type="submit" value="查询" style ="height : 36px;border:1px;background-color:#00bee7;color:#fff;width:72px;border-radius: 3px;">
</form>
<div style="height:100px;width:240px;margin:0px auto;" align="center">
	<p><a href="welcome_mag.html" align="center" >返回服务选择页面</a></p>
</div>
</body>
	</html>

select_opt.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查询结果显示界面</title>
</head>
<style type = "text/css">
   	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/
</style>
<body>

	<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">查询的结果如下</div>
	<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
<div style="border:1px;border-color: #00bee7" align="center" >
<center>
	<table style="border: solid 1px;border-color:#09F;" align ="center" width=60% >
    <tr >
    	<td width=90px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">学号</td>
    	<td width=90px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">姓名</td>
    	<td width=90px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">班级</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">性别</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">语文</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">英语</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">数学</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">理综</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">总分</td>
    </tr>

</div>
<?php
	function get_str($str){
		$val = ($_POST[$str])?$_POST[$str]:null;
		return $val;
	}
	$sel = get_str("check");
	if($sel == null){
?>
    <script type="text/javascript">
		alert("输入不能为空,请重新输入");
		window.location.href="select.html";
    </script>
<?php
	}
	$con = mysql_connect("localhost","root","root");
	if(!$con){
		?>
        <script type="text/javascript">
			alert("数据库连接失败");
			window.location.href="select.html";
		</script>
        <?php
		}
		mysql_select_db("SGMSystem");
		if($sel != "所有"){
		$sql = "select * from stu_info where id = $sel";
		$info = mysql_query($sql,$con);
		$num = mysql_num_rows($info);
		if($num){
			$row = mysql_fetch_row($info);
			echo $row[0].$row[1].$row[2].$row[3].$row[4].$row[5].$row[6].$row[7].$row[8];
			}
		else{
			?>
            <script type="text/javascript">
				alert("查询失败");
				window.location.href="select.html";
            </script>
            <?php
			}
			if($row){
				echo "<tr><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[0]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[1]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[2]."</td><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[3]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[4]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[5]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[6]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[7]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[8]."</td></tr>";
			}
		}
		else{
			$sql = "select * from stu_info";
			$info = mysql_query($sql,$con);
			$num = mysql_num_rows($info);
			if($num){
				//查询成功
				while($row = mysql_fetch_row($info)){
					//显示所有信息
					echo "<tr><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[0]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[1]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[2]."</td><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[3]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[4]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[5]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[6]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[7]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[8]."</td></tr>";
				}
			}
			else{
			?>
	            <script type="text/javascript">
					alert("查询失败");
					window.location.href="select.html";
	            </script>
            <?php
			}
		}
?>
</table>
</center>
<div style="height:100px;width:240px;margin:0px auto;" align="center">
	<p><a href="select_mag.html" align="center" >返回查询页面</a></p>
</div>
</body>
</html>

insert.html:

<html>
<head>
	<title>增添学生成绩数据</title>
	<meta charset="utf-8">
	<style type = "text/css">
   	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/
</style>
	</head>
	<body>
	<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">请填写表单以添加数据</div>
	<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
	<div style="border:1px;border-color: #00bee7" align="center">
		<form action="mysql_opt.php" method="post" style="margin:35px auto;padding:30px;box-shadow:1px 1px 2px 1px #aaaaaa;
		border-radius: 3px;width:380px;">
		<ul>
			<li>
				学号:<input type="text" name="number" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入学号(唯一)">
			</li>
			<li>
				姓名:<input type="text" name="stuname" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入姓名">
			</li>
			<li>
				班级:<input type="text" name="class" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入班级(可全使用字符)">
			</li>
			<li>
				性别:<input type="text" name="sex" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入性别">
			</li>
			<li>
				语文:<input type="text" name="chinese" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入语文成绩(满分150)">
			</li>
			<li>
				数学:<input type="text" name="maths" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入数学成绩(满分150)">
			</li>
			<li>
				英语:<input type="text" name="english" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入英语成绩(满分150)">
			</li>
			<li>
				理综:<input type="text" name="synthesis" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入英语成绩(满分300)">
			</li>
			
		</ul>
		<input type="submit" value="提交" style ="height : 36px;border:1px;background-color:#00bee7;color:#fff;width:72px;border-radius: 3px;">
	</form>
	</div>
	<div style="height:100px;width:240px;margin:0px auto;" align="center">
	<p><a href="welcome_mag.html" align="center" >返回服务选择页面</a></p>
</div>
	</body>
</html>

mysql_opt.php:

<html>
<head>
	<title>数据库后台操作</title>
	<meta charset="utf-8">
	</head>
	<body>
		<?php
			//这个页面主要是对插入进行处理
			function get_str($str){
				$val = ($_POST[$str])?$_POST[$str]:null;
				return $val;
			}
			$num = get_str("number");//接收学号
			$name = get_str("stuname");//接收姓名
			$class = get_str("class");//接收班级
			$sex = get_str("sex");//接收性别
			$chi = get_str("chinese");//接收语文成绩
			$mat = get_str("maths");//接收数学成绩
			$eng = get_str("english");//接收英语成绩
			$syn = get_str("synthesis");//接收理综成绩
			if($num==0 or $name ==null or $class == null or $sex ==null or $chi ==0 or $mat ==0 or $eng ==0 or $syn ==0){?>
				<script type="text/javascript">
					alert("数据输入有误,请重新输入");
					window.location.href="insert.html";
				</script>
				<?php
			}
			$sum = $chi + $mat + $eng + $syn;//计算总分
			$con = mysql_connect("localhost","root","root");
			if(!$con){
				?>
				<script type="text/javascript">
					alert("数据库连接失败");
					window.location.href="insert.html";
				</script>
				<?php
			}
			$sql = "insert into stu_info (id,姓名,班级,性别,语文,数学,英语,理综,总分)
			values($num,'$name','$class','$sex',$chi,$mat,$eng,$syn,$sum)";
			mysql_select_db("SGMSystem");
			$info = mysql_query($sql,$con);
			if($info){
				?>
				<script type="text/javascript">
					alert("写入成功");
					window.location.href="insert.html";
				</script>
				<?php
			}
			else{
				?>
				<script type="text/javascript">
					alert("写入失败");
					window.location.href="insert.html";
				</script>
				<?php
			}
			mysql_close($con);
		?>
	</body>
</html>

delete.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>删除服务界面</title>
<style>
	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/

</style>
</head>
<body>

	<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">请输入学生的学号以删除学生信息</div>
	<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
<div style="border:1px;border-color: #00bee7" align="center" >
<form action="delete_opt.php" method="post" style="margin: 35px auto;padding:30px;box-shadow: 1px 1px 2px 1px #aaaaaa;border-radius: 3px;width:380px;">
	<input type="text" name="delete" class ="" style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:200px;" placeholder="请输入要删除学生信息的学号">
	     
	<input type="submit" value="删除" style ="height : 36px;border:1px;background-color:#00bee7;color:#fff;width:72px;border-radius: 3px;">
</form>
	<div style="height:100px;width:240px;margin:0px auto;" align="center">
	<p><a href="welcome_mag.html" align="center" >返回服务选择页面</a></p>
</div>

	</body>
</html>

delete_opt.php:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>删除操作后台执行页面</title>
</head>
<?php
 	function get_str($str){
 		$val = ($_POST[$str])?$_POST[$str]:null;
 		return $val;
 	}
 	$number = get_str("delete");

 	$con = mysql_connect("localhost","root","root");
 	if(!$con){
 		?>
 		<script type="text/javascript">
 			alert("数据库连接失败");
 			window.location.href="delete.html";
 		</script>
 		<?php
 	}
 	$sql = "select * from stu_info where id = $number";
 	mysql_select_db("SGMSystem");
 	$info = mysql_query($sql,$con);
 	$num = mysql_num_rows($info);
 	if(!$num){
 		?>
 	<script type="text/javascript">
 		alert("找不到该同学,请重新输入学号");
 		window.location.href="delete.html";
 	</script>
 	<?php }
 	else{
 		//找到了该同学,进行删除操作
 		$sql = "delete from stu_info where id = $number";
 		$info = mysql_query($sql,$con);
 		if($info){
 	    	//删除成功
 	    	?>
 	    	<script type="text/javascript">
 	    		alert("删除成功");
 	    		window.location.href="delete.html";
 	    	</script>
 	    	<?php
 	    }
 	    else{
 	    	//删除失败
 	    	?>
 	    	<script type="text/javascript">
 	    		alert("删除失败");
 	    		window.location.href="delete.html";
 	    	</script>
 	    	<?php
 	    }
 	}
?>

select_stu.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>信息查询界面</title>
<style type = "text/css">
   	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/
</style>
</head>
<!--这是学生端的查询界面,不提供返回管理员页面的接口-->
<body>
<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">
	<p>请输入学生的学号进行查询操作</p>
	<p>如果要查询所有学生信息请输入“所有”进行查询</p>
</div>
<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
<form action="select_opt_stu.php" method="post" style="margin: 35px auto;padding:30px;box-shadow: 1px 1px 2px 1px #aaaaaa;border-radius: 3px;width:380px;">
	<input  type="text" name="check"  style = "background-color: rgb(250, 255, 189) !important; border-radius: 3px;box-shadow: none; color: rgb(0, 0, 0);line-height: 26px;width:240px;" placeholder="请输入要查询学生的学号">
	          
	<input type="submit" value="查询" style ="height : 36px;border:1px;background-color:#00bee7;color:#fff;width:72px;border-radius: 3px;">
</form>

</body>
	</html>

select_opt_stu.php:(和管理员端的后台页面只是返回的超链接不同)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>查询结果显示界面</title>
</head>
<style type = "text/css">
   	a{text-decoration: none;font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);}
	a:link{color:#00FFFF;}/*未访问的颜色 蓝色*/
	a:hover{color:#FF00FF;}/*鼠标放上去的颜色(没起作用) 紫色*/
	a:visited{color:#00FFFF;}/*访问过的颜色 蓝色*/
	a:active{color:#FF00FF;}/*选定的代码 紫色*/
</style>
<body>

	<div style="font-size:25px;font-family:微软雅黑;color:rgb(98,94,91);" align="center">查询的结果如下</div>
	<div style="height:180px;width:180px;margin:0px auto;" align="right">
	<p sytle="text-align:center;">
<img src="宅舞.gif" width="160" height="160" align="right"/>
</p>
</div>
<div style="border:1px;border-color: #00bee7" align="center" >
<center>
	<table style="border: solid 1px;border-color:#09F;" align ="center" width=60% >
    <tr >
    	<td width=90px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">学号</td>
    	<td width=90px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">姓名</td>
    	<td width=90px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">班级</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">性别</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">语文</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">英语</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">数学</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">理综</td>
    	<td width=60px style="font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);">总分</td>
    </tr>

</div>
<?php
	function get_str($str){
		$val = ($_POST[$str])?$_POST[$str]:null;
		return $val;
	}
	$sel = get_str("check");
	if($sel == null){
?>
    <script type="text/javascript">
		alert("输入不能为空,请重新输入");
		window.location.href="select.html";
    </script>
<?php
	}
	$con = mysql_connect("localhost","root","root");
	if(!$con){
		?>
        <script type="text/javascript">
			alert("数据库连接失败");
			window.location.href="select.html";
		</script>
        <?php
		}
		mysql_select_db("SGMSystem");
		if($sel != "所有"){
		$sql = "select * from stu_info where id = $sel";
		$info = mysql_query($sql,$con);
		$num = mysql_num_rows($info);
		if($num){
			$row = mysql_fetch_row($info);
			echo $row[0].$row[1].$row[2].$row[3].$row[4].$row[5].$row[6].$row[7].$row[8];
			}
		else{
			?>
            <script type="text/javascript">
				alert("查询失败");
				window.location.href="select.html";
            </script>
            <?php
			}
			if($row){
				echo "<tr><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[0]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[1]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[2]."</td><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[3]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[4]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[5]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[6]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[7]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[8]."</td></tr>";
			}
		}
		else{
			$sql = "select * from stu_info";
			$info = mysql_query($sql,$con);
			$num = mysql_num_rows($info);
			if($num){
				//查询成功
				while($row = mysql_fetch_row($info)){
					//显示所有信息
					echo "<tr><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[0]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[1]."</td> <td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[2]."</td><td width=90px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[3]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[4]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[5]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[6]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[7]."</td><td width=60px style='font-size:20px;font-family:微软雅黑;color:rgb(98,94,91);'>".$row[8]."</td></tr>";
				}
			}
			else{
			?>
	            <script type="text/javascript">
					alert("查询失败");
					window.location.href="select.html";
	            </script>
            <?php
			}
		}
?>
</table>
</center>
<div style="height:100px;width:240px;margin:0px auto;" align="center">
	<p><a href="select_stu.html"  align="center" >返回查询页面</a></p>
</div>
</body>
</html>

效果图如下:

查询信息输入页面


删除信息输入页面


插入信息输入页面


这个系统还不完美,还有很多可以改进的地方,如果有什么好的修改建议,欢迎一起讨论^_^

猜你喜欢

转载自blog.csdn.net/haohulala/article/details/80547000