匹配在数据库中获取的用户名和密码

我需要匹配我在数据库中获取的用户名和密码。现在的问题是我无法匹配您在下面看到的图像的用户名和密码:

http://img3.mukewang.com/60cd5831000103ba13620623.jpg

这是我的代码如下:


HTML


    <body>  

          <div class="container box">  

           <div class="form-group">  

            <h3 align="center">Live Username Available or not By using PHP Ajax Jquery</h3><br />  

            <label>Enter Username</label>  

            <input type="text" name="username" id="username" class="form-control" />

            <input type="password" name="password" id="password" class="form-control" />



            <span id="availability"></span>

            <br /><br />

            <button type="button" name="register" class="btn btn-info" id="register" disabled>Register</button>

            <br />

           </div>  

           <br />  

           <br />  

          </div>  

  </body>  

jQuery 脚本- 这是在用户名和密码匹配或不匹配后显示匹配可用性的地方


<script>  

 $(document).ready(function(){  

  $('#username, #password').blur(function(){


    var username = $('#username').val();

    var password = $('#password').val();


     $.ajax({

      url:'check.php',

      method:"POST",

      data:{user_name:username, password:password},

      success:function(data)

      {

        console.log(data);

       if(data != '0')

       {

        $('#availability').html('<span class="text-danger">Username and Password not Match</span>');

        $('#register').attr("disabled", true);

       }

       else

       {

        $('#availability').html('<span class="text-success">Username and Password Available</span>');

        $('#register').attr("disabled", false);

       }


      }


     })


  });

 });  

</script>




牛魔王的故事
浏览 206回答 3
3回答

拉莫斯之舞

我认为您的条件在客户端脚本中是错误的。如果用户名和密码匹配,那么它将返回大于 0 的值。在这种情况下,您的代码应该是success:function(data)&nbsp; {&nbsp; &nbsp; console.log(data);&nbsp; &nbsp; if(data == 0)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $('#availability').html('<span class="text-danger">Username and Password not Match</span>');&nbsp; &nbsp; &nbsp; $('#register').attr("disabled", true);&nbsp; &nbsp; }&nbsp;&nbsp; &nbsp; else&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; $('#availability').html('<span class="text-success">Username and Password Available</span>');&nbsp; &nbsp; &nbsp; $('#register').attr("disabled", false);&nbsp; &nbsp; }&nbsp; &nbsp;}

慕莱坞森

你可以试试这个:if(isset($_POST["username"], $_POST["password"]))&nbsp;&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp;&nbsp;$username = $_POST["username"];&nbsp;&nbsp;$password = $_POST["password"];&nbsp;&nbsp;$query = mysql_query("SELECT username, password FROM admin WHERE username = '".$username."' AND&nbsp; password = '".$password."'");&nbsp;$result=$connect->query($query);&nbsp; &nbsp; &nbsp; &nbsp; if(mysql_num_rows($result) > 0 )&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_SESSION["logged_in"] = true;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $_SESSION["username"] = $name;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; else&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; echo 'The username or password are incorrect!';&nbsp; &nbsp; &nbsp; &nbsp; }}

叮当猫咪

FOR MINUS POINTS这是 OP 也遇到的问题的解决方案。请看主线评论。谢谢你。只需将您的 POST 值包装到md5 函数中。$password&nbsp;=&nbsp;md5(mysqli_real_escape_string($connect,&nbsp;$_POST["password"]));或者可以尝试在数据库中使用MD5。$query&nbsp;=&nbsp;"SELECT&nbsp;*&nbsp;FROM&nbsp;admin&nbsp;WHERE&nbsp;username&nbsp;=&nbsp;'".$username."'&nbsp;AND&nbsp;password&nbsp;=&nbsp;MD5('".$password."')&nbsp;";那么密码哈希应该等于数据库哈希。
打开App,查看更多内容
随时随地看视频慕课网APP