search

Home  >  Q&A  >  body text

mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, bool given in when php queries the database

<?php    include "../common/dbsession.php";    session_start();    if(isset($_SESSION['user'])){       header('location:../content/home.php');    }else{       if(isset($_POST['vcode'])){            if($_POST['vcode']==$_SESSION['vcode']){                //核对数据表user                $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("Error: %s\n", mysqli_error($conn)); exit(); }*/                $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['user']=$_POST['zh']; //登陆成功                      echo "3";                   }else{                       echo "0";//账户密码错误                    }                }else{ //表中不存在                    echo "2";//账户不存在                                }            }else{              echo "1";//验证码不对              //session_destroy();            }        exit;      }    }?><!doctype html><html> <head> <title>User login</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>Welcome to log in</div> <form action='' method='post' >                                                              /div> ="pw" placeholder="Please enter password" autocomplete="off" >                                                              </div> </form>                                                                                                                                                                                                                                                              ".vcode").val(), "zh":$( ".zh").val(), "pw":$(".pw").val()}, function(res){ alert(res); alert(res); if(res==0){ window.location.href "../content/home.php"; alert(" Account input error, please re -enter! ");} Else if (res == 3) {alert (" Account password input error, please re -enter! "); Or contact the administrator!")                                                                                                          lt;/body></html>

顾于顾于1168 days ago1260

reply all(2)I'll reply

  • autoload

    autoload2021-11-29 10:48:25

    if (!$res) {  
      printf("Error: %s\n", mysqli_error($conn));    
      exit();
      }

    Do not comment this statement to see if it is a mysqli_fetch_assoc() parameter problem or a sql statement problem

    reply
    0
  • 顾于

    Thank you, boss. I have it. I have two lines of code with multiple symbols.

    顾于 · 2021-11-30 12:10:02
  • Cancelreply