Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • What Is Wrong With Number Of Rows Count Function ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 61
    Answer it

    Guys & Ladies,

    This LOGIN.php was working lastnight and so I don't know why not now.

    The ELSE at 53 gets triggered even though I have typed the right password!

    What do you think of line 16 ? ...

    if($numrows >1)

    I tried the following but no luck:

    if($numrows)

    if($numrows !=0)

    if($numrows ==2)

     

    In the past, they worked, though. What is wrong, do you reckon?

    [php]
    
    <?php
    session_start();
    require "conn.php";
    require "site_details.php";
    
    if(isset($_POST["member_login_submit"]))
    {
        if(!empty($_POST["member_login_username_or_email"]) && !empty($_POST["member_login_password"]))
        {
            $member_login_username_or_email = trim(strip_tags(strtolower(mysqli_real_escape_string($conn,$_POST["member_login_username_or_email"]))));
            $member_login_password = trim(strip_tags(mysqli_real_escape_string($conn,$_POST["member_login_password"])));
            
            $sql = "SELECT * FROM users WHERE usernames='".$member_login_username_or_email."' OR emails='".$member_login_username_or_email."' AND passwords='".$member_login_password."'";
            $result = mysqli_query($conn,$sql);
            $numrows = mysqli_num_rows($result);
            if($numrows >1)
            {        
                while ($row = mysqli_fetch_assoc($result))
                {
                    $db_username = $row["usernames"];
                    $db_password = $row["passwords"];
                    $db_email = $row["emails"];
                                            
                    if  ($member_login_username_or_email == $db_username && $member_login_password == $db_password || $member_login_username_or_email == $db_email && $member_login_password == $db_password)            
                    {
                        $_SESSION["user"] = $member_login_username_or_email;           
                        if(!empty($_POST["member_login_remember"]))
                        {
                            setcookie("member_login_username_or_email", $member_login_username_or_email, time()+ (10 * 365 * 24 * 60 * 60));
                            setcookie("member_login_password", $member_login_password, time()+ (10 * 365 * 24 * 60 * 60));                        
                        }
                        else
                        {
                            if(isset($_COOKIE["member_login_username_or_email"]))
                            {    
                                setcookie("member_login_username_or_email", "", "");
                            }
                            if(isset($_COOKIE["member_login_password"]))
                            {    
                                setcookie("member_login_password", "", "");
                            }        
                        }
                        header("location:home.php");            
                    }
                    else
                    {
                        $message = "Invalid login!";
                    }    
                }
            }
            else
            {
                $message = "Something is wrong! Try again later!";
            }        
        }
        else
        {
            $message = "You must input your Username and Password!";    
        }
    }    
    
    ?>
    <!DOCTYPE html>
    <html>
    <head>
    <title><?php $site_name?> Member Login Page</title>
      <meta charset="utf-8">
    </head>
    <body>
    <div class = "container">
    <form method="post" action="">
    <center><h3><?php $site_name ?> Member Login Form</h3></center>
    <div class="text-danger">
    <?php
    if(isset($message))
    {
        echo $message;
    }
    ?>
    <div class="form-group">
    <center><label>Username/Email:</label>
    <input type="text" placeholder="Enter Username or Email" name="member_login_username_or_email" value="<?php if(isset($_COOKIE["member_login_username_or_email"])) echo $_COOKIE["member_login_username_or_email"]; ?>"</center>
    </div>
    <div class="form-group">
    <center><label>Password:</label>
    <input type="password" placeholder="Enter password" name="member_login_password" value="<?php if(isset($_COOKIE["member_login_password"])) echo $_COOKIE["member_login_password"]; ?>"></center>
    </div>
    <div class="form-group">
    <center><label>Remember Login Details:</label>
    <input type="checkbox" name="member_login_remember" /></center>
    </div>
    <div class="form-group">
    <center><input type="submit" name="member_login_submit" value="Login" class="button button-success" /></center>
    </div>
    <div class="form-group">
    <center><font color="red" size="3"><b>Forgot your password ?</b><br><a href="member_login_password_reset.php">Reset it here!</a></font></center>
    <center><font color="red" size="3"><b>Not registered ?</b><br><a href="member_register.php">Register here!</a></font></center>
    </form>
    </div>
    </body>
    </html>
    
    [/php]

     

 0 Answer(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: