doujia7162 2013-09-21 08:56
浏览 34
已采纳

有一段时间后,登录我的网站失败了

I have been utilizing this forum to take help in creating my first PHP website. I have most of the things up and running, but am facing an issue with my login. If a new user signs up and login to the website, it works perfectly fine, but if I open the login database even once or if I view the list of users in the admin panel, all the previous user login fails and no one can login with those credentials again even when they are still present in the database. Any help? Below is my login form code:

<?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";
}
}
?>
  • 写回答

1条回答 默认 最新

  • doure8758 2013-09-21 09:08
    关注
    <?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";
        }
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)