alert(\"姓名不能为空\");";
//这里的句子是弹出窗口后就停止运行下面的代码
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 "";
exit();
}
//sql语句
$sql = "insert into xs(xm,xb,cssj,kcs) values('$name','$sex','$birthday','$kcs')";
//运行
$result = mysqli_query($conn,$sql);
//判断结果
if($result)
{
//输出结果
echo "";
//此句再写一条sql语句进行执行,得到我们想要输出的结果
$result = mysqli_query($conn,"select * from xs where xm = '$name'");
//从结果中取一行作数字数组,就下面的输出要用到
$row = mysqli_fetch_array($result);
//输出表格头部
echo "姓名 | 性别 | 出生日期 | 已修课程数 | ";
//输出表格内容
echo "".$row['xm']." | ";
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['cssj']." | ";
echo "".$row['kcs']." |
";
echo "
";
}
else
{
//这是没录入成功不能输出内容就弹出窗口提示
echo "";
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 "";
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 " 姓名 | 性别 | 出生日期 | 已修课程数 |
";
echo "".$row['xm']." | ";
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['cssj']." | ";
echo "".$row['kcs']." |
";
echo "
";
}
else{
echo "";
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 " 性别 | 已修课程数 | 出生日期 | 姓名 |
";
while($row = mysqli_fetch_array($result))
{
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['kcs']." | ";
echo "".$row['cssj']." | ";
echo "".$row['xm']." |
";
}
echo "
";
}
else
{
echo "";
exit();
}
}
else
{
$sql = "select * from xs where xb = '$sex'";
$result = mysqli_query($conn,$sql);
if(!mysqli_num_rows($result))
{
echo "";
exit();
}
else{
echo "姓名 | 性别 | 出生日期 | 已修课程数 | ";
while($row = mysqli_fetch_array($result))
{
echo "".$row['xm']." | ";
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['cssj']." | ";
echo "".$row['kcs']." |
";
}
echo "
";
}
}
}
else if(strlen($kcs))
{
$sql = "select xm,xb,cssj,kcs from xs where kcs = '$kcs'";
$result = mysqli_query($conn,$sql);
if($result)
{
echo " 姓名 | 性别 | 出生日期 | 已修课程数 |
";
while($row = mysqli_fetch_array($result))
{
echo "".$row['xm']." | ";
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['cssj']." | ";
echo "".$row['kcs']." |
";
}
echo "
";
}
else{
echo "";
exit();
}
}
else{
$sql = "select * from xs";
$result = mysqli_query($conn,$sql);
if($result)
{
echo " 姓名 | 性别 | 出生日期 | 已修课程数 |
";
while($row = mysqli_fetch_array($result))
{
echo "".$row['xm']." | ";
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['cssj']." | ";
echo "".$row['kcs']." |
";
}
echo "
";
}
else{
echo "";
exit();
}
}
}
if(isset($_POST['删除']))
{
if(!strlen($name))
{
echo "";
exit();
}
$sql = "select xm from xs where xm = '$name'";
$result = mysqli_query($conn,$sql);
if(!mysqli_num_rows($result)){
echo "";
exit();
}
$sql = "delete from xs where xm = '$name'";
$result = mysqli_query($conn,$sql);
if($result)
{
echo "";
exit();
}
else{
echo "";
exit();
}
}
if(isset($_POST['更新']))
{
if(!strlen($name)||!strlen($sex)||!strlen($birthday)||!strlen($kcs))
{
echo "";
exit();
}
$sql = "select xm from xs where xm = '$name'";
$result = mysqli_query($conn,$sql);
if(!mysqli_num_rows($result)){
echo "";
exit();
}
$sql = "update xs set xb = '$sex',cssj = '$birthday',kcs = '$kcs' where xm = '$name'";
$result = mysqli_query($conn,$sql);
if($result)
{
echo "";
$result = mysqli_query($conn,"select * from xs where xm = '$name'");
$row = mysqli_fetch_array($result);
echo "姓名 | 性别 | 出生日期 | 已修课程数 | ";
echo "".$row['xm']." | ";
echo "";
if($row['xb']==1)echo"男";
else echo"女";
echo " | ";
echo "".$row['cssj']." | ";
echo "".$row['kcs']." |
";
echo "
";
}
else
{
echo "";
exit();
}
}
//写完之后记得关闭连接数据库
mysqli_close($conn);
?>