搜索
登录页面点击登录后查询不出数据,无法成功登陆,但是在数据库中进行查询操作是可以成功的,是什么原因呢?
移动用户-2386203
移动用户-2386203 2021-03-07 17:16:01
[MySQL讨论组]

<?php

session_start();

error_reporting(E_ERROR); 

$zh=$_POST['zh'];

$password=$_POST['password'];

$user=$_POST['user'];

if(!isset($user)){

    echo "<script> alert('请选择用户类型');</script>";

    echo "<script> history.go(-1);</script>";

}

$conn=mysqli_connect("localhost","8admin","8admin")or die('连接数据库失败');

$db=mysqli_select_db($conn,"8_com");

$sql1="SELECT*FROM admin WHERE admin_id ='$zh' AND password='$password' ";

$sql2="select * from teacher where teach_id ='$zh' and password='$password' ";

$sql3="select * from student where stuno ='$zh' and password='$password' ";

mysqli_query($conn,"set names utf8");

switch($user){

    case 1:$result=mysqli_query($conn,$sql)or die('查询不到'); 

               $row = mysqli_fetch_array($conn,$result);

               $count=$row[0];

               if($count!=""){

                   $url="index_admin.php";

                   $_SESSION['admin_name']=$row['name'];

                   $_SESSION['admin_id']=$row['admin_id'];

                   echo "<script type='text/javascript'>"."location.href='".$url."'"."</script>";

               }

               else {

                    echo "<script> alert('账户或密码错误');</script>";

                    echo "<script> history.go(-1);</script>";

                }

                break;

    case 2:$result=mysqli_query($sql2,$conn);  

        $result=mysqli_query($sql2,$conn)or die('查询不到'); 

               $row = mysqli_fetch_array($result);

               $count=$row[0];

               if($count!=""){

                   $url="index_teacher.php";

                   $_SESSION['teacher_name']=$row['name'];

                   $_SESSION['teacher_id']=$row['teach_id'];

                   echo "<script type='text/javascript'>"."location.href='".$url."'"."</script>";

               }

               else {

                    echo "<script> alert('账户或密码错误');</script>";

                    echo "<script> history.go(-1);</script>";

                }

                break;

    case 3:$result=mysqli_query($sql3,$conn);  

        $result=mysqli_query($sql3,$conn)or die('查询不到'); 

               $row = mysqli_fetch_array($result);

               $count=$row[0];

               if($count!=""){

                   $url="index_stu.php";

                   $_SESSION['stu_name']=$row['name'];

                   $_SESSION['stu_id']=$row['stuno'];

                   echo "<script type='text/javascript'>"."location.href='".$url."'"."</script>";

               }

               else {

                    echo "<script> alert('账户或密码错误');</script>";

                    echo "<script> history.go(-1);</script>";

                }

                break;

    default :break;

}  

mysqli_close($conn);

?>

移动用户-2386203
移动用户-2386203

全部回复(1)
灭绝师太

后端断点打印是否能够拿到数据

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号