我在Login.php页面输入正确的电子邮件ID和密码,但显示错误

时间:2014-04-12 14:26:12

标签: php phpmyadmin

我只输出else部分,用户没有登录。 我首先连接到数据库,然后从表名register_tbl获取数组以验证特定用户。

<?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>

1 个答案:

答案 0 :(得分:0)

首先,您不应在新代码中使用mysql_*函数。为什么不?请在此处阅读:Why Shouldn't I use mysql_* functions in PHP?

另一方面,检查您的密码是否在数据库上进行了哈希处理。如果是,它将永远不会与输入的那个匹配。您需要在输入的密码上使用相同的哈希值,然后比较两者。

可能是我没见过的其他东西。