一、安装phpstudy+Dreamweaver软件并测试
1、安装PHP(已完成)
2、安装Dreamweaver(之前已安装好了)
3、测试并创建了第一个PHP页面,为加强巩固做多了几个练习
二、学生信息管理系统
1、建立pxscj数据库并建立xs表,kc表,cj表和user表(在Mysql-front完成)
2、储存过程
3、登录页面设计(登录用户:root 登录密码:root 与数据库pxscj连接
代码如下:
在这里插入代码片<!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">
body {
background-color: white;
}
div{
height: 700px;
width: 90%;
margin-left: auto;
margin-right: auto;
background-color:white;
}
.cc {
padding-top: 20px;
padding-left: 20px;
}
header {
height: 8%;
background-image:url(images/%E7%99%BB%E5%BD%95%E9%A1%B5%E9%9D%A2.png);
opacity: 80%;
}
article {
background-color: white;
height: 87%;
}
footer {
background-color: #903;
height: 5%;
}
.aa{
font-family:"宋体";
font-size:24px;
margin-left:400px;
padding-top:100px;
text-align:center;
}
.bb{
width:40px;
height:20px;
margin-bottom:20px;
margin-left:5px;
padding-left:400px;
}
.p1{
font-family:"宋体";
font-size:16px;
margin-top:20px;
margin-right:50px;
padding-left:450px;
}
</style>
</head>
<body>
include("fun.php");
$username=@$_POST['username'];
$password=@$_POST['password'];
echo $username;
$success_tips="";
if(!empty($username))
{
$s_sql="select * from user where username='$username' and password='$password'";
$s_result=$db->query($s_sql);
if($s_result && $s_result->rowCount() !=0)
{
echo "";
}
else
{
echo "";
}
}
?>
<div>
<header class="cc"><span class="aa">惠州学院学生管理系统</span></header>
<article class="cc">
<form name="login11" action="login11.php" method="post">
<p class="p1">欢迎登录!</p>
<div class="bb"><input name="username" type="text" placeholder="输入用户名" /></div>
<div class="bb"><input name="password" type="password" placeholder="请输入密码" /></div>
<br />
<div class="bb"><input type="submit" value="登录" ></div>
</form>
</article>
<footer class="cc"><span>计算机科学与工程学院</span></footer>
</div>
</body>
</html>
学生成绩管理系统
"0" leftMargin="0" bottomMargin="0" rightMargin="0">
"675" border="0" align="center" cellpadding="0" cellspacing="0" style="width: 778px; ">
"images/学生信息管理系统.gif" width="790" height="97">
"images/底.jpg" width="790" height="32">
header('Content-Type: text/html;charset=GB2312');
?>
session_start(); //启动SESSION
?>
<html>
<head>
<title>学生管理</title>
</head>
<body bgcolor="#CCCCCC">
$XM = $_SESSION['XM'];
$XB = $_SESSION['XB'];
$CSSJ = $_SESSION['CSSJ'];
$KCS = $_SESSION['KCS'];
$StuName = $_SESSION['StuName'];
?>
<form method="post" action="studentAction.php" enctype="multipart/form-data">
<table>
<tr>
<td>
<table>
<tr>
<td>姓名:</td><td><input type="text" name="xm" value="$XM;?>"/></td>
</tr>
<tr>
<td>性别:</td>
if(@$XB == 1) {
?>
<td>
<input type="radio" name="xb" value="1" checked="checked">男
<input type="radio" name="xb" value="0">女
</td>
}else {
?>
<td>
<input type="radio" name="xb" value="1">男
<input type="radio" name="xb" value="0" checked="checked">女
</td>
}
?>
</tr>
<tr>
<td>出生年月:</td><td><input type="text" name="cssj" value="$CSSJ;?>"/></td>
</tr>
<tr>
<td>照片:</td><td><input name="photo" type="file"></td>
</tr>
<tr>
<td></td>
<td>
<!-- 使用img控件调用showpicture.php页面用于显示照片,studentname用于保存当前学生姓名值,time()函数用于产生一个时间戳,防止服务器读取缓存中的内容-->
//echo "";
//if($row['ZP'])
echo "";
//echo "";
//else
//echo "暂无照片";
?>
已修课程
$StuName')"; //执行存储过程
$result = $db->query(iconv('GB2312', 'UTF-8', $cj_sql));
$xmcj_sql = "select * from XMCJ_VIEW"; //从XMCJ_VIEW表中查询出学生成绩信息
$cj_rs = $db->query($xmcj_sql);
//输出表格
echo "<table border=1>";
echo "<tr bgcolor=#CCCCC0>";
echo " 课程名 成绩 ";
while(list($KCM, $CJ) = $cj_rs->fetch(PDO::FETCH_NUM)) {
//获取成绩结果集
$KC = iconv('UTF-8', 'GB2312', $KCM);
echo "$KC $CJ "; //在表格中显示输出"课程名-成绩"信息
}
echo "
";
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</form>
</body>
</html>
(1)查询功能
(2)录入功能
(3)删除功能
(4)更新功能
以上功能的代码:
include "fun.php";
include "studentManage.php";
$StudentName = @$_POST['xm']; //姓名
$Sex = @$_POST['xb']; //性别
$Birthday = @$_POST['cssj']; //生日
$tmp_file = @$_FILES["photo"]["tmp_name"]; //文件被上传后在服务端储存的临时文件
$handle = @fopen($tmp_file,'rb'); //打开文件
$Picture = @base64_encode(fread($handle, filesize($tmp_file))); //读取上传的照片变量并编码
$s_sql = "select XM, KCS from XS where XM ='$StudentName'"; //查找姓名、已修课程数信息
$s_result = $db->query(iconv('GB2312', 'UTF-8', $s_sql));
/**以下为各学生管理操作按钮的代码*/
//录入功能
if(@$_POST["btn"] == '录入') {
//单击"录入"按钮
if($s_result->rowCount() != 0) //要录入的学生姓名已经存在时提示
echo "";
else {
if(!$tmp_file) {
//没有上传照片的情况
$insert_sql = "insert into XS values('$StudentName', $Sex, '$Birthday', 0, NULL, NULL)";
}else {
$insert_sql = "insert into XS values('$StudentName', $Sex, '$Birthday', 0, NULL, '$Picture')";
}
$insert_result = $db->query(iconv('GB2312', 'UTF-8', $insert_sql));
if($insert_result->rowCount() != 0) {
$_SESSION['StuName'] = $StudentName;
echo "";
}else
echo "";
}
}
//删除功能
if(@$_POST["btn"] == '删除') {
//单击"删除"按钮
if($s_result->rowCount() == 0) //要删除的学生姓名不存在时提示
echo "";
else {
//处理姓名存在的情况
list($XM, $KCS) = $s_result->fetch(PDO::FETCH_NUM);
if($KCS != 0) //学生有修课记录时提示
echo "";
else {
//删除操作
$del_sql = "delete from XS where XM ='$StudentName'";
$del_affected = $db->exec(iconv('GB2312', 'UTF-8', $del_sql));
if($del_affected) {
$_SESSION['StuName'] = 0;
echo "";
}
}
}
}
//更新功能
if(@$_POST["btn"] == '更新'){
//单击"更新"按钮
$_SESSION['StuName'] = $StudentName; //将用户输入的姓名用SESSION保存
if(!$tmp_file) //若没有上传文件则不更新照片列
$update_sql = "update XS set XB =$Sex, CSSJ ='$Birthday' where XM ='$StudentName'";
else
$update_sql = "update XS set XB =$Sex, CSSJ ='$Birthday', ZP='$Picture' where XM ='$StudentName'";
$update_affected = $db->exec(iconv('GB2312', 'UTF-8', $update_sql));
if($update_affected)
echo "";
else
echo "";
}
//查询功能
if(@$_POST["btn"] == '查询') {
//单击"查询"按钮
$_SESSION['StuName'] = $StudentName; //将姓名传给其他页面
$sql = "select XM, XB, CSSJ, KCS from XS where XM ='$StudentName'"; //查找姓名对应的学生信息
$result = $db->query(iconv('GB2312', 'UTF-8', $sql));
if($result->rowCount() == 0) //判断该学生是否存在
echo "";
else {
list($XM, $XB, $CSSJ, $KCS) = $result->fetch(PDO::FETCH_NUM);
$_SESSION['XM'] = iconv('UTF-8', 'GB2312', $XM);
$_SESSION['XB'] = $XB;
$_SESSION['CSSJ'] = $CSSJ;
$_SESSION['KCS'] = $KCS;
echo "";
}
}
?>
5、点击成绩管理,跳转页面
(1)查询功能
(2)录入功能
(3)删除功能(删除林涣淇 数据库应用技术 98分)
全部功能代码如下:
<html>
<head>
<title>成绩管理</title>
</head>
<body bgcolor="#CCCCCC">
<form method="post">
<table>
<tr>
<td>
课程名:
<!-- 以下JS代码是为了保证在页面刷新后,下拉列表中仍然保持着之前的选中项 -->
<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)">
echo "";
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', 'GB2312', $KCM);
echo ">$KC";
}
?>
</select>
<script type="text/javascript">
var selectedIndex = getCookie("select_1");
if(selectedIndex != null) {
document.getElementById("select_1").selectedIndex = selectedIndex;
}
</script>
</td>
<td><input name="btn" type="submit" value="查询"></td>
</tr>
<tr>
<td>
姓名:
<input type="text" name="xm" size="5">
成绩:
<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">
<table border=1 width="285">
<tr bgcolor=#CCCCC0>
<td align="center">姓名</td>
<td align="center">成绩</td>
</tr>
include "fun.php";
//单击【查询】按钮
if(@$_POST["btn"] == '查询') {
//单击"查询"按钮
$CourseName = $_POST['kcm'];
$cj_sql = "select XM, CJ from CJ where KCM ='$CourseName'"; //查找该课程对应的成绩单
$cj_result = $db->query(iconv('GB2312', 'UTF-8', $cj_sql));
while(list($XM, $CJ) = $cj_result->fetch(PDO::FETCH_NUM)) {
//获取查询结果集
$Name = iconv('UTF-8', 'GB2312', $XM);
//在表格中显示输出"姓名-成绩"信息
echo "$Name $CJ ";
}
}
?>
</table>
</td>
<td></td>
</tr>
</table>
</form>
</body>
</html>
$CourseName = $_POST['kcm']; //获取提交的课程名
$StudentName = $_POST['xm']; //获取提交的姓名
$Score = $_POST['cj']; //获取提交的成绩
$cj_sql = "select * from CJ where KCM ='$CourseName' and XM ='$StudentName'"; //先从数据库中查询该生该门课的成绩
$result = $db->query(iconv('GB2312', 'UTF-8', $cj_sql));
//单击【录入】按钮
if(@$_POST["btn"] == '录入') {
if($result->rowCount() != 0) //查询结果不为空,表示该成绩记录已经存在
echo "";
else {
//不存在才可以添加
$insert_sql = "insert into CJ(XM, KCM, CJ) values('$StudentName', '$CourseName', '$Score')"; //添加新记录
$insert_result = $db->query(iconv('GB2312', 'UTF-8', $insert_sql)); //执行操作
if($insert_result->rowCount() != 0)
echo "";
else
echo "";
}
}
//单击【删除】按钮
if(@$_POST["btn"] == '删除') {
if($result->rowCount() != 0) {
//查询结果不为空,该成绩记录存在可删除
$delete_sql = "delete from CJ where XM ='$StudentName' and KCM ='$CourseName'"; //删除该记录
$del_affected = $db->exec(iconv('GB2312', 'UTF-8', $delete_sql)); //执行操作
if($del_affected)
echo "";
else
echo "";
}else //不存在该记录,无法删
echo "";
}
?>
三、实验报告心得
刚开始接触这个课程设计,给出的模板我还看不懂,后来慢慢在自己的钻研下,一步一步完成设计报告,虽然只有两个管理模板,但改部分代码有些吃力,甚至有点做到崩溃,一开始数据库没连接好,页面连接不上,再是页面乱码,是因为字符集问题,所以修改了代码中字符集问题,储存过程也出了问题,导致在学生管理页面显示不出姓名和成绩,在同学帮助下发现问题并解决问题。后来有照片录入失败,修改代码,改变照片大小,也完成它的功能。总之,做好一个学生信息管理系统要有耐心和细心,还有很多需要提升自己的能力。
你可能感兴趣的:(mysql)