php查询数据库时出现mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in
顾于
顾于 2021-11-27 22:18:58
0
2
1255

<?php    include "../common/dbsession.php";    会话开始();    if(isset($_SESSION['user'])){       header('location:../content/home.php');    }else{       if(isset($_POST['vcode'])){            if($_POST['vcode']==$_SESSION['vcode']){                  //核对数据表用户                $conn=mysqli_connect("10.21 .54.99:3306","c322","20210409","c322");                 $sql="select * from `user` where `email`='".$_POST['zh']."'";                $res=mysqli_query($conn,$sql);                mysqli_fetch_array($res);                /*if (!$res){  printf("错误:%s\n", mysqli_error($conn)); 出口(); }*/                $row=mysqli_fetch_assoc($res);                if(!$conn){       die("连接失败".mysqli_connect_error()); }                //var_dump($res);                if(isset($row['pw'])){//表中                   if(md5($_POST['pw'])==$row['pw']){                      $_SESSION=[];                      $_SESSION['用户']=$_POST['zh']; //登陆成功 echo "3";                   }else{                       echo "0";//账户密码错误                    }                }else{ //表中不                    echo "2";//账户不存在                        }            }else{              echo "1";//验证码正确              //session_destroy ();            } 出口;      }    }?><!doctype html><html>  <head>      <title>用户登录</title>      <meta charset="utf-8">      <script type="text/javascript" src="../resource/jquery-3.2.1.min.js"></script> <link rel="style.css" href="../login.css">  </head>  <body>     <div style="text-align:center;margin-top:20px;">     <div>欢迎登陆</div>     <form action='' method='post'>        <img src="../resource/kcaptcha/index.php">          <div>        <input type="text" class="vcode" placeholder="请输入验证码">          </div>          <div>        <input type="text" class="zh" placeholder="请输入作为账户的邮箱">          </div>          <div>        <input type="password" class="pw" placeholder="请输入密码" autocomplete="off" >          </div>          <div>        <input type="submit" values="提交" onclick="login();">          </div>    </form>          <script>              function login(){                 $.post(                   "./login.php",                   {"vcode":$(".vcode").val(),                    "zh":$(".zh").val(),                    "pw":$(".pw").val()},                   function(res){                      alert(res);                       if(res==0){                           window.location.href="../content/home.php";                       }else if(res==1){                          alert("验证码输入错误,请重新输入!");                       }else if(res==2){                          alert("账户输入错误,请重新输入!");                       }else if(res==3){                          alert("账户密码输入错误,请重新输入!");                       }else{                         alert("服务异常,请刷新页面重试或联系管理员!")                       }                   }                );                         }                    </script>  </body></html>

顾于
顾于

全部回复(1)
demo
if (!$res) {  
  printf("Error: %s\n", mysqli_error($conn));    
  exit();
  }

这个语句不要注释,看看是mysqli_fetch_assoc()参数问题,还是sql语句问题

  • 回复 谢谢大佬,我成了,有两行代码多符号了
    顾于 作者 2021-11-30 12:10:02
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板