<?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>
这个语句不要注释,看看是mysqli_fetch_assoc()参数问题,还是sql语句问题