query(iconv('UTF-8', '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('UTF-8', '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('UTF-8', '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('UTF-8', '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('UTF-8', 'UTF-8', $sql)); if($result->rowCount() == 0) //判断该学生是否存在 echo ""; else { list($XM, $XB, $CSSJ, $KCS) = $result->fetch(PDO::FETCH_NUM); $_SESSION['XM'] = iconv('UTF-8', 'UTF-8', $XM); $_SESSION['XB'] = $XB; $_SESSION['CSSJ'] = $CSSJ; $_SESSION['KCS'] = $KCS; echo ""; } } ?>