如何修复我的PHP登录系统错误

时间:2013-10-13 12:19:07

标签: php mysql

我使用PHP& amp;创建了一个简单的登录系统。 MySQL,但我发现1错误,我不知道如何解决它,所以你能帮助我吗?错误来自第$_session['username'] = $dbusername;

session_start();

$username = $_POST['username'];
$password = $_POST['password'];

if ($username && $password) {

    $connect = mysql_connect("localhost", "root", "") or die("couldnt connect to database");
    mysql_select_db("login") or die("couldnt find database");

    $query = mysql_query("SELECT * FROM users WHERE username='$username'");
    $numrows = mysql_num_rows($query);

    if ($numrows != 0) {
        while ($row = mysql_fetch_assoc($query)) {
            $dbusername = $row['username'];
            $dbpassword = $row['password'];
        }

        if ($username == $dbusername && $password == $dbpassword) {
            echo "Login successfull.<a href='membersarea.php'>click here to enter members area</a>
            $_session['username'] = $dbusername;
        }
        else
            echo "incorrect password";
    }
    else
        die("That username doesnt exist");
}
else
    die("please enter a username and password");

2 个答案:

答案 0 :(得分:4)

的结尾
echo "Login successfull.

似乎不见了。或者至少“未公开。

答案 1 :(得分:0)

$_session 必须为大写字母,而echo'd successfull...需要一个结束的分号和双引号。

更改

$_session['username'] = $dbusername;

为:

$_SESSION['username']=$dbusername;

和此(缺少分号和双引号)

echo "Login successfull.<a href='membersarea.php'>click here to enter members area</a>

更改为

echo "Login successfull. <a href='membersarea.php'>click here to enter members area</a>";