You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
4.8 KiB

<?php
header('Content-Type: text/html; charset=utf-8');
?>
<html>
<head>
<title>成绩管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<style type="text/css">
body {
background-image: url(images/%E8%83%8C%E6%99%AF.gif);
background-repeat: no-repeat;
background-size: cover;
color: #FFF;
font-size: larger;
}
.zt {
font-size: 36px;
font-weight: bold;
}
</style>
</head>
<body>
<form method="post">
<p>&nbsp;</p>
<table>
<tr>
<td align="left" class="zt"><table>
<tr></tr>
<tr>
<td align="left" class="zt"><table width="494" height="189">
<tr>
<td width="365" class="zt"> 课程名:
<script type="text/javascript">
function setCookie(name, value) {
var exp = new Date();
exp.setTime(exp.getTime() + 24 * 60 * 60 * 1000);
document.cookie = name + "=" + escape(value) + ";expires=" + exp.toGMTString();
}
function getCookie(name) {
var regExp = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
var arr = document.cookie.match(regExp);
if(arr == null) {
return null;
}
return unescape(arr[2]);
}
</script>
<select name="kcm" id="select_1"
onclick="setCookie('select_1',this.selectedIndex)">
<?php
echo "<option>请选择</option>";
require "fun.php";
$kcm_sql = "select distinct KCM from KC"; //查找所有的课程名
$kcm_result = $db->query($kcm_sql);
while(list($KCM) = $kcm_result->fetch(PDO::FETCH_NUM)) { //输出课程名到下拉框中
$KC = iconv('UTF-8', 'UTF-8', $KCM);
echo "<option value=$KC>$KC</option>";
}
?>
</select>
<script type="text/javascript">
var selectedIndex = getCookie("select_1");
if(selectedIndex != null) {
document.getElementById("select_1").selectedIndex = selectedIndex;
}
</script></td>
<td width="100"><input name="btn" type="submit" value="查询"></td>
</tr>
<tr>
<td class="zt"> 姓名:
<input type="text" name="xm" size="5">
&nbsp;
成绩:
<input type="text" name="cj" size="2"></td>
<td><input name="btn" type="submit" value="录入">
<input name="btn" type="submit" value="删除"></td>
</tr>
<tr>
<td align="left" class="zt"><table border=1 width="285">
<tr bgcolor=#CCCCC0>
<td align="center">姓名</td>
<td align="center">成绩</td>
</tr>
<?php
include "fun.php";
if(@$_POST["btn"] == '查询') {
$CourseName = $_POST['kcm'];
$cj_sql = "select XM, CJ from CJ where KCM ='$CourseName'";
$cj_result = $db->query(iconv('UTF-8', 'UTF-8', $cj_sql));
if ($cj_result->rowCount() == 0)
echo "<script>alert('该门课程无学生选!');location.href='scoreManage.php';</script>";
else {
while (list ($XM, $CJ) = $cj_result->fetch(PDO::FETCH_NUM))
{
$Name = iconv('UTF-8', 'UTF-8', $XM);
echo "<tr><td align=center>$Name&nbsp;</td><td align=center>$CJ</td></tr>";
}
}
}
?>
</table></td>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
</tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
</form>
</body>
</html>
<?php
@$CourseName = $_POST['kcm'];
@$StudentName = $_POST['xm'];
@$Score = $_POST['cj'];
$cj_sql = "select * from CJ where KCM ='$CourseName' and XM ='$StudentName'";
$result = $db->query(iconv('UTF-8', 'UTF-8', $cj_sql));
if(@$_POST["btn"] == '录入')
{if($result->rowCount() != 0)
echo "<script>alert('该记录已经存在!');location.href='scoreManage.php';</script>";
else
{
$insert_sql = "insert into CJ(XM, KCM, CJ) values('$StudentName', '$CourseName', '$Score')";
$insert_result = $db->query(iconv('UTF-8', 'UTF-8', $insert_sql));
if($insert_result->rowCount() != 0)
echo "<script>alert('添加成功!');location.href='scoreManage.php';</script>";
else
echo "<script>alert('添加失败,请确保有此学生!');location.href='scoreManage.php';</script>";
}
}
if(@$_POST["btn"] == '删除') {
if($result->rowCount() != 0) {
$delete_sql = "delete from CJ where XM ='$StudentName' and KCM ='$CourseName'";
$del_affected = $db->exec(iconv('UTF-8', 'UTF-8', $delete_sql));
if($del_affected)
echo "<script>alert('删除成功!');location.href='scoreManage.php';</script>";
else
echo "<script>alert('删除失败,请检查操作权限!');location.href='scoreManage.php';</script>";
}else
echo "<script>alert('该记录不存在!');location.href='scoreManage.php';</script>";
}
?>