|
|
<!--显示学生数据信息的页面-->
|
|
|
|
|
|
|
|
|
|
|
|
<?php
|
|
|
session_start();/*暂时保存我们输入的信息*/
|
|
|
?>
|
|
|
|
|
|
<!DOCTYPE html>
|
|
|
<html>
|
|
|
<body>
|
|
|
|
|
|
<?php
|
|
|
|
|
|
include("connect.php");/*连接数据库,这个数据库的前四个字母在下面的时候写成这样$conn就是连接数据库的意思*/
|
|
|
|
|
|
//获取表单数据
|
|
|
$name = $_POST['xm'];
|
|
|
$sex = $_POST['xb'];
|
|
|
$birthday = $_POST['cssj'];
|
|
|
$kcs = $_POST['kcs'];
|
|
|
|
|
|
//接下来就是分情况讨论
|
|
|
|
|
|
//如果按下录入键
|
|
|
if(isset($_POST['录入']))
|
|
|
{
|
|
|
|
|
|
//这里就是判断是否输入了姓名
|
|
|
if(!strlen($name) )//加!表示没有输入姓名,strlen()是一个函数
|
|
|
{
|
|
|
|
|
|
//php语句,弹出一个窗口提示括号里的内容
|
|
|
echo "<script>alert(\"姓名不能为空\");</script>";
|
|
|
|
|
|
//这里的句子是弹出窗口后就停止运行下面的代码
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
//sql语句,跟我们学的一样的写记得加引号
|
|
|
$sql = "select xm from xs where xm = '$name'";
|
|
|
|
|
|
//运行sql语句,用到了mysqli_query()函数
|
|
|
$result = mysqli_query($conn,$sql);//括号里的第一个是连接数据库,后面一个是sql语句执行
|
|
|
|
|
|
//if语句里面用到了一个函数,来判断运行结果是否为真
|
|
|
if(mysqli_num_rows($result))
|
|
|
{
|
|
|
//这里跟上面一样的
|
|
|
echo "<script>alert(\"学生已存在\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
//sql语句
|
|
|
$sql = "insert into xs(xm,xb,cssj,kcs) values('$name','$sex','$birthday','$kcs')";
|
|
|
|
|
|
//运行
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
|
|
|
//判断结果
|
|
|
if($result)
|
|
|
{
|
|
|
//输出结果
|
|
|
echo "<script>alert(\"录入成功\")</script>";
|
|
|
|
|
|
//此句再写一条sql语句进行执行,得到我们想要输出的结果
|
|
|
$result = mysqli_query($conn,"select * from xs where xm = '$name'");
|
|
|
|
|
|
//从结果中取一行作数字数组,就下面的输出要用到
|
|
|
$row = mysqli_fetch_array($result);
|
|
|
|
|
|
//输出表格头部
|
|
|
echo "<table border <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>已修课程数</th></tr>";
|
|
|
|
|
|
//输出表格内容
|
|
|
echo "<tr><th>".$row['xm']."</th>";
|
|
|
echo "<th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 60px>".$row['kcs']."</th></tr>";
|
|
|
echo "</table>";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
//这是没录入成功不能输出内容就弹出窗口提示
|
|
|
echo "<script>alert(\"录入失败\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//下面一样的我就不写注释了
|
|
|
|
|
|
//按下查询按钮
|
|
|
if(isset($_POST['查询']))
|
|
|
{
|
|
|
//这里的句子你可以根据实际情况来分,我这个写的有点晕
|
|
|
//就输入什么,查到什么
|
|
|
//不输入的时候是否可以进行查询balabala的
|
|
|
|
|
|
if(strlen($name))
|
|
|
{
|
|
|
|
|
|
}
|
|
|
if(strlen($name))
|
|
|
{
|
|
|
$sql = "select xm from xs where xm = '$name'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if(!mysqli_num_rows($result))
|
|
|
{
|
|
|
echo "<script>alert(\"学生不存在\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
if(strlen($sex))
|
|
|
{
|
|
|
$sql = "select xb,xm from xs where xm = '$name' and xb = '$sex'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if($resul)
|
|
|
{
|
|
|
$result = mysqli_query($conn,"select * from xs where xm = '$name' and xb ='$sex'");
|
|
|
$row = mysqli_fetch_array($result);
|
|
|
echo "<table border=1> <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>已修课程数</th></tr>";
|
|
|
echo "<tr><th>".$row['xm']."</th>";
|
|
|
echo "<th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 60px>".$row['kcs']."</th></tr>";
|
|
|
echo "</table>";
|
|
|
}
|
|
|
else{
|
|
|
echo "<script>alert(\"不存在满足条件的同学\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(strlen($sex))
|
|
|
{
|
|
|
|
|
|
if(strlen($kcs))
|
|
|
{
|
|
|
$sql = "select xb,kcs from xs where xb = '$sex' and kcs = '$kcs'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
|
|
|
if(mysqli_num_rows($result))
|
|
|
{
|
|
|
|
|
|
//这里是输出多行内容的,用到了while(),记得表格的头部要写在while()外面,接下来的按照这种方法一直写就ok了
|
|
|
$row = mysqli_fetch_array($result);
|
|
|
|
|
|
echo "<table border=1> <tr><th>性别</th><th>已修课程数</th><th>出生日期</th><th>姓名</th></tr>";
|
|
|
|
|
|
while($row = mysqli_fetch_array($result))
|
|
|
{
|
|
|
echo "<tr><th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th>".$row['kcs']."</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 70px>".$row['xm']."</th></tr>";
|
|
|
}
|
|
|
echo "</table>";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
echo "<script>alert(\"无该性别和选修课程数的学生\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
else
|
|
|
{
|
|
|
$sql = "select * from xs where xb = '$sex'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if(!mysqli_num_rows($result))
|
|
|
{
|
|
|
echo "<script>alert(\"无该性别的学生\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
else{
|
|
|
echo "<table border <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>已修课程数</th></tr>";
|
|
|
while($row = mysqli_fetch_array($result))
|
|
|
{
|
|
|
echo "<tr><th>".$row['xm']."</th>";
|
|
|
echo "<th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 60px>".$row['kcs']."</th></tr>";
|
|
|
}
|
|
|
echo "</table>";
|
|
|
}
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else if(strlen($kcs))
|
|
|
{
|
|
|
$sql = "select xm,xb,cssj,kcs from xs where kcs = '$kcs'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
|
|
|
if($result)
|
|
|
{
|
|
|
echo "<table border=1> <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>已修课程数</th></tr>";
|
|
|
while($row = mysqli_fetch_array($result))
|
|
|
{
|
|
|
echo "<tr><th>".$row['xm']."</th>";
|
|
|
echo "<th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 60px>".$row['kcs']."</th></tr>";
|
|
|
}
|
|
|
echo "</table>";
|
|
|
}
|
|
|
else{
|
|
|
echo "<script>alert(\"该已修课程数下无学生数据\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
else{
|
|
|
$sql = "select * from xs";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
|
|
|
if($result)
|
|
|
{
|
|
|
echo "<table border=1> <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>已修课程数</th></tr>";
|
|
|
while($row = mysqli_fetch_array($result))
|
|
|
{
|
|
|
echo "<tr><th>".$row['xm']."</th>";
|
|
|
echo "<th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 60px>".$row['kcs']."</th></tr>";
|
|
|
}
|
|
|
echo "</table>";
|
|
|
}
|
|
|
else{
|
|
|
echo "<script>alert(\"数据库中暂无学生信息,请开始录入\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
if(isset($_POST['删除']))
|
|
|
{
|
|
|
if(!strlen($name))
|
|
|
{
|
|
|
echo "<script>alert(\"姓名不能为空\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
$sql = "select xm from xs where xm = '$name'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if(!mysqli_num_rows($result)){
|
|
|
echo "<script>alert(\"学生不存在\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
$sql = "delete from xs where xm = '$name'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if($result)
|
|
|
{
|
|
|
echo "<script>alert(\"删除成功\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
else{
|
|
|
echo "<script>alert(\"删除失败\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if(isset($_POST['更新']))
|
|
|
{
|
|
|
|
|
|
if(!strlen($name)||!strlen($sex)||!strlen($birthday)||!strlen($kcs))
|
|
|
{
|
|
|
echo "<script>alert(\"请重新填写,确保信息填写完整\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
$sql = "select xm from xs where xm = '$name'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if(!mysqli_num_rows($result)){
|
|
|
echo "<script>alert(\"学生不存在\");</script>";
|
|
|
exit();
|
|
|
}
|
|
|
|
|
|
$sql = "update xs set xb = '$sex',cssj = '$birthday',kcs = '$kcs' where xm = '$name'";
|
|
|
$result = mysqli_query($conn,$sql);
|
|
|
if($result)
|
|
|
{
|
|
|
echo "<script>alert(\"更新成功\")</script>";
|
|
|
$result = mysqli_query($conn,"select * from xs where xm = '$name'");
|
|
|
$row = mysqli_fetch_array($result);
|
|
|
echo "<table border <tr><th>姓名</th><th>性别</th><th>出生日期</th><th>已修课程数</th></tr>";
|
|
|
echo "<tr><th>".$row['xm']."</th>";
|
|
|
echo "<th width= 40px>";
|
|
|
if($row['xb']==1)echo"男";
|
|
|
else echo"女";
|
|
|
echo "</th>";
|
|
|
echo "<th width =120px>".$row['cssj']."</th>";
|
|
|
echo "<th width = 60px>".$row['kcs']."</th></tr>";
|
|
|
echo "</table>";
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
echo "<script>alert(\"更新失败,请重试\")</script>";
|
|
|
exit();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//写完之后记得关闭连接数据库
|
|
|
mysqli_close($conn);
|
|
|
?>
|
|
|
</body>
|
|
|
</html>
|