0

我一直在利用这个论坛来帮助创建我的第一个 PHP 网站。我已经启动并运行了大部分内容,但我的登录遇到了问题。如果一个新用户注册并登录网站,它工作得很好,但是如果我打开登录数据库一​​次,或者如果我在管理面板中查看用户列表,所有以前的用户登录都失败,没有人可以登录再次使用这些凭据,即使它们仍然存在于数据库中。有什么帮助吗?以下是我的登录表单代码:

<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<html>
    <head>
    </head>
    <body>
        <table border="1" width="100%">
        <form action="user.php" method="post">
        <tr>
           <td><label for="u_name">Your Email-id:</label></td>
           <td><input type="text"name="u_name" id="u_name" placeholder="Enter email-id" required="required"/></td>
        </tr>
        <tr>
           <td><label for="u_password">Password:</label></td>
           <td><input type="password" name="u_password" id="u_password" placeholder="Enter password" required="required"/></td>
        </tr>
        <tr>
           <td colspan="2" align="center"><input type="submit" name="sub" value="login"/></td>
        </tr>
        </table>
        </form>
     </body>
</html>
<?php 
if(isset($_POST['sub']))
{
    $u_name=$_POST['u_name'];
    $u_password=$_POST['u_password'];
    include ("connection.php");
    $w="select * from signup";
    $b=mysql_query($w) or die(mysql_error()."in query $w");
    while($row=mysql_fetch_array($b))
    {
     $a=$row['email_id'];
     $u=$row['password'];
    }
if ($u_name==$a && $u_password==$u)
{
    $_SESSION['loggedin']=true;
    $_SESSION['user_email']=$_POST['u_name'];
    $_SESSION['user_pass']=$_POST['u_password'];
    echo '<meta http-equiv="refresh" content="0; url=homepage.php">';
}
else
{
    echo "Your username or password is incorrect.Please try again";
}
}
?>
4

1 回答 1

1
<?php 
if(isset($_POST['sub']))
{
    $u_name=$_POST['u_name'];
    $u_password=$_POST['u_password'];
    include ("connection.php");
    $w="select * from signup where email_id = '$u_name' AND password = '$u_password'";
    $b=mysql_query($w) or die(mysql_error()."in query $w");
    $num_rows = mysql_num_rows($b);
    if($num_rows > 0)
    {
        $row=mysql_fetch_array($b);
        $_SESSION['loggedin']=true;
        $_SESSION['user_email']=$_POST['u_name'];
        $_SESSION['user_pass']=$_POST['u_password'];
        echo '<meta http-equiv="refresh" content="0; url=homepage.php">';
    }
    else
    {
         echo "Your username or password is incorrect.Please try again";
    }
}
?>
于 2013-09-21T09:08:42.747 回答