dongyixun0634 2014-11-28 09:38
浏览 18

登录表单验证问题

I have a query for Username and Password validation. I am able to do Field Validation but not LOGIN validation.

The coding being used is given below. Alert for Login Success or Failure is not being displayed i mean checking for usersername and password match/ mismatch is not happening. The function being used is not getting to Checkpassword.php to give the message/ alert. Could you please advise on how to go about this.

<script>
    $(document).ready(function () {
        //* validation
        $('#login').validate({
            onkeyup: false,
            errorClass: 'error',
            validClass: 'valid',
            rules: {
                user_email: {
                    required: true,
                    email: true
                },
                user_pass: {
                    required: true,
                    minlength: 6
                }
            },
            messages: {
                user_email: {
                    required: 'Please enter your email ID',
                    email: 'Please enter a valid email ID'
                },
                user_pass: {
                    required: 'Please enter your password',
                    minlength: 'Please enter at least 6 characters.'
                }
            },
            highlight: function (element) {
                $(element).closest('.f_er').addClass("f_error");

            },
            unhighlight: function (element) {
                $(element).closest('.f_er').removeClass("f_error");

            }
        });
    });

    /* Login validation */
    $(document).on('click', '#login1', function () {
        $('#login').validate();
        var validate_login = $('#login').valid();
        if (validate_login === true)
        {
            var post_data = $('#login').serialize();
            $.ajax({
                type: "POST",
                url: "checkpassword.php",
                data: post_data,
                success: function (msg) {
                    var resultarr = msg;
                    // $(".page-loader").remove();
                    var success_msg = $.trim(resultarr[0]);
                    if (success_msg === "SUCCESS")
                    {
                        //var login_token = resultarr[1];
                        // $.cookie("covogue_login_token", login_token, {
                        //    expires: 30
                        //});
                        window.location.href = "blog.php";
                    }
                    if (success_msg === "FAIL")
                    {
                        $("#error_li").show();
                        $("#login_result").text('Please enter a valid email ID and password.');
                        alert("Please enter a valid email ID and password.");
                    }
                },
                error: function () {
                    //$(".page-loader").remove();
                    // sticky_notifications('Oops!! Try that again in a few moments.',{type: "error"});
                    alert("Try Again");
                }
            });
        } else {
            alert("Try Again1");
        }
    });
</script>

<div class="user_login">
    <form method="post" id="login" name="login" class="f_er">
        <!--<label><div id="error" style="color:red; text-align: center;"></div></label>-->
        <label>Email</label>
        <input type="text" name="user_email" id="user_email" autofocus/> 
        <br />

        <label>Password</label>
        <input type="password" name="user_pass" id="user_pass"/>
        <br />
        <li style="display:none;" id="error_li"><span id="login_result" class="error_color"></span></li>
        <div class="action_btns">
            <div class="one_half"><a href="#" class="btn back_btn"><i class="fa fa-angle-double-left"></i> Back</a></div>
            <div class="one_half last"><button type="button" name="login1" id="login1" class="btn btn_red">Login</button></div>
        </div>
    </form>
    <a href="forgot_password.php" class="forgot_password">Forgot password?</a>
</div>

checkpassword.php

<?php
    include 'admin/config.php';
    $username = $_POST['user_email'];
    $password = $_POST['user_pass'];
    $check = mysqli_query($con,"select username,
    password from blog_login where username = '$username' and password = '$passwod'");
    $count = mysqli_num_rows($check);

    if( $count == '1' ){
        echo "SUCCESS";
    } else {
        echo "FAIL";
    }
?>
  • 写回答

2条回答 默认 最新

  • dqiz20794 2014-11-28 09:44
    关注
    select username,password from blog_login where username = '$username' and password = '$passwod'
    

    Its just a spelling mistake in your query near PASSWORD.. you gave "passwod" it should be "$password"..

    $password = $_POST['user_pass'];
    

    So,

    select username,password from blog_login where username = '$username' and password = '$password'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示