dongshen6060
dongshen6060
2016-04-29 07:45

无法检查我的登录信息

已采纳

I need to check whether the username and password inputted by the user is correct so they can log in. If it's correct, it will run a line of codes from the javascript code, if not, it will just alert that username/password is wrong. The problem is, the page just refreshes, it doesn't run the javascript code even if the username & password is right and also this appears:

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in D:\xampp\htdocs\statistics\index.php on line 195

(The error above is fixed, the only one not working now is the javascript code)

Here is my PHP code for the log in:

        if(isset($_POST['proceedToLogin'])) {
            if((!empty($_POST['username'])) && (!empty($_POST['password']))) {
               $uname = $_POST['username'];
               $pword = $_POST['password'];
               $selup = "SELECT * admin WHERE Username ='$uname'AND Password ='$pword'";
               $checkup = mysqli_query($conn, $selup);
                 if(mysqli_num_rows($checkup) > 0) {
                    print '<script type="text/javascript">';
                    print 'goHome(1);';
                    print 'return false;';
                    print '</script>';
                 }
            }
        }

the javascript code that's supposed to run:

function goHome(source){
            $('#bluearrow').css('margin-left','-100px');
            $('#orangearrow').css('margin-left','-200px');
            $('#greenarrow').css('margin-left','-300px');
            $('#grayarrow').css('margin-left','-400px');

            $("body").css("overflow","hidden");
            if(source == 1)
            $('#login').animate({ opacity: 'hide',  left: '-200px', }, 'slow', 'linear', function() {
                document.getElementById('username').value ="";
                document.getElementById('password').value ="";
                $("#login").hide();
                $("#login").css('margin-left', '280px');
            });
            else if(source == 2)
            $('#addApplicant').animate({ opacity: 'hide',  left: '-200px', }, 'slow', 'linear', function() {
                $(this).hide();
                $(this).css('left','30px');
            });

            $("#menu").hide().show();
            $("#bluearrow").hide();
            $("#orangearrow").hide();
            $("#greenarrow").hide();
            $("#grayarrow").hide();
            $(".menu-label").hide();
            $('html,body').scrollTop(0);

            setTimeout(function(){
                $("#bluearrow").hide().show("slide", { direction: "left" }, 1500);
            },500); 
            setTimeout(function(){
                $("#orangearrow").hide().show("slide", { direction: "left" }, 1500);
            },1300); 
            setTimeout(function(){
                $("#greenarrow").hide().show("slide", { direction: "left" }, 1500);
            },2000); 
            setTimeout(function(){
                $("#grayarrow").hide().show("slide", { direction: "left" }, 1500);
            },2700); 
            setTimeout(function(){
                $('span').animate({ opacity: 'show',  left: '50px', }, 'slow', 'linear', function() {
                $(this).show();
            });
            },4100); 
    }

They're both in the same file, btw.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • douruobokui58233 douruobokui58233 5年前

    Replace:

    $selup = "SELECT * admin WHERE Username ='$uname'AND Password ='$pword'";
    

    AND

     print '<script type="text/javascript">';
                        print 'goHome(1);';
                        print 'return false;';
                        print '</script>';
    

    With

    $selup = "SELECT * from admin WHERE Username ='$uname'AND Password '$pword'";
    

    AND

    print '<script type="text/javascript">';
    print '$(document).ready(function(){';
                        print 'goHome(1);';
                        print '});';
                        print '</script>';
    
    点赞 评论 复制链接分享
  • dsf6281 dsf6281 5年前

    Replace

     $selup = "SELECT * admin WHERE Username ='$uname'AND Password ='$pword'";
    

    with

    $selup = "SELECT * from admin WHERE Username ='$uname'AND Password ='$pword'";
    
    点赞 评论 复制链接分享