简体   繁体   中英

I am Entering Correct Email id and Password in my Login.php page, But Shows Error

I am getting output only the else part and users are not logged in. I have first connected to database ,and then fetch array from the table name register_tbl to validate a particular user.

<?php
error_reporting(0);

require("connect_db.php"); //connecting to database

    if(isset($_POST['submit']))
    {

        $emailid = mysql_escape_string($_POST['emailid']);
        $password = mysql_escape_string($_POST['password']);



        $sql = "SELECT * FROM register_tbl WHERE emailid = '$emailid' AND password='$password'";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);


        if($row["emailid"]== $emailid && $row["password"]== $password)
        {    
            echo"You are a validated user. and successfully loged in";
        }
        else
        {
            echo"Sorry, your credentials are not valid, Please try again.";
        }//this else part is displayed
    }


?>

//html form to login 
<html>
<body>
<h1>Login Form</h1>
<form action ="login.php" method ="POST">
Email Id: <input type = "text" name="emailid" /></br>
Password: <input type ="password" name ="password" /></br>
<input type="submit" name="submit" value="submit" />
</form>
<body>
</html>

First of all, you shouldn't use mysql_* functions in new code. Why not? Read here: Why Shouldn't I use mysql_* functions in PHP?

On the other hand, check if your password is hashed on the database. If it is, it will never match the one that is entered. You would need to use the same hash on the entered password, and then compare the two.

Might be something else that I'm not seeing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM