我已经使用global $db 在后面函数中还是无法使用
getMessage(); } ?>
<?php
include"conn.php";//包含连接数据库的PHP文件
include"stuInfo.php";//包含前端页面的PHP页
//以post方式接收stuinfo.PHP页面提交的表单数据
$sno=@$_POST['sno'];
$sname=@$_POST['sname'];
$ssex=@$_POST['ssex'];
$sbirthday=@$_POST['sbirthday'];
$speciality=@$_POST['speciality'];
$tc=@$_POST['tc'];
$search_sql="select * from student where sno='$sno'";
$search_result=$db->query($search_sql);
//录入功能
if(@$_POST['btn']=='录入'){
$count=$search_result->rowCount();
if($search_result->rowCount()!=0)//要录入的学号已经存在时提示
echo"<script>alert('该学生已经存在!');location.href='stuInfo.php';</script>";
else{
$ins_sql="insert into student values('$sno','$sname','$ssex','$sbirthday','$speciality','$tc')";
$ins_result=$db->query($ins_sql);
if($ins_result->rowCount()!=0){
echo"<script>alert('录入成功!'); location.href='stuInfo.php';</script>";
}else
echo"<script>alert('录入失败,请检查输入信息!'); location.href='stuInfo.php';</script>";
}
}
//删除功能
if(@$_POST['btn']=='删除'){
$_SESSION['sno']=$sno;
if($search_result->rowCount()==0)//要删除的学号不存在时提示
echo"<script>alert('该学生不存在!');location.href='stuInfo.php';</script>";
else{
$del_sql="delete from student where sno='$sno'";
$del_affected=$db->exec($del_sql);
if($del_affected){
$_SESSION['sno']='';
$_SESSION['sname']='';
$_SESSION['ssex']='';
$_SESSION['sbirthday']='';
$_SESSION['speciality']='';
$_SESSION['tc']='';
echo"<script>alert('删除成功!'); location.href='stuInfo.php';</script>";
}
}
}
//更新功能
if(@$_POST['btn']=='更新'){
$_SESSION['sno']=$sno;
$upd_sql="update student set sno='$sno',sname='$sname',ssex='$ssex',sbrithay='$sbirthday',speciality='$speciality',tc='$tc' where sno='$sno'";
$upd_affected=$db->exec($upd_sql);
if(upd_affected){
$_SESSION['sno']='';
$_SESSION['sname']='';
$_SESSION['ssex']='';
$_SESSION['sbirthday']='';
$_SESSION['speciality']='';
$_SESSION['tc']='';
echo"<script>alert('更新成功!');location.href='stuInfo.php';</script>";
}
else
echo"<script>alert('更新失败,请检查输入信息!'); location.href='stuInfo.php';</script>";
}
//查询功能
if(@$_POST['btn']=='查询'){
$_SESSION['sno']=$sno;
$find_sql="select * from student where sno='$sno'";
$find_result=$db->query($find_sql);
if($find_result->rowCount()==0)
echo"<script>alert('该学生不存在!');location.href='stuInfo.php';</script>";
else{
list($sno,$sname,$ssex,$sbirthday,$speciality,$tc)=$find_result->fetch(PDO::FETCH_NUM);
$_SESSION['sno']=$sno;
$_SESSION['sname']=$sname;
$_SESSION['ssex']=$ssex;
$_SESSION['sbirthday']=$sbirthday;
$_SESSION['speciality']=$speciality;
$_SESSION['tc']=$tc;
echo"<script>location.href='stuInfo.php';</script>";
}
}
?>
###### 我想要达到的结果
解决这个报错让他正常使用