-4

我的登录表单不显示。我得到一个空白页。

所以请发布正确的代码,以便我可以轻松替换它。我是 php 新手,所以我的代码不会像你的那样超级专业。

这是我的代码:

<?php
session_start();
?>
<head>
  <meta http-equiv=""Content-Type" content="text/html"; charset=utf-8 />
  <title>Member Register</title>
</head>
<body><?php
    $form = "<form action='./login.php' method='post'>

               <table>
                 <tr>
                   <td>Username:</td>
                   <td><input type='text' name='user' /></td>
                 </tr>
                 <tr>
                   <td>Password:</td>
                   <td><input type='password' name='password' /></td>
                 </tr>
                 <tr>
                   <td></td>
                   <td><input type='submit' name='loginbtn' value='Login' /></td>
                 </tr>
               </table>
             </form>";

    if ($_POST['loginbtn']) {
        $user = $_POST['user'];
        $password = $_POST['password'];

        if ($user) {
            if ($password) {

                require("connect.php");

                $password = md5(md5("Ji5t63s".password."v5h2ih47");

                $query = mysql_query("SELECT * FROM users WHERE username='$user'");
                $numrows = mysql_num_rows($query);
                if ($numrows == 1) {
                    $row = mysql_fetch_assoc($query);
                    $dbid = $row['id'];
                    $dbuser = $row['username'];
                    $dbpass = $row['password'];
                    $dbactive = $row['active'];

                    if ($password == $dbpass){
                        if ($dbactive == 1){
                            $_SESSION['userid'] = $dbid;
                            $_SESSION['username'] = $dbuser;

                            echo "You have been logged in as <b>$dbuser</b>. <a href="./member.php">Click here</a> to go to the member page.";

                        }
                        else
                            echo "you must activate your account to login. $form";
                    }
                    else
                        echo "you did not entered a correct password. $form";
                }
                else
                    echo "The user you entered was not found. $form";
                    mysql_close();

            }
            else
                echo "You must enter you password. $form";
        }
        else
            echo "You must enter your username. $form";
    }
    else
        echo $form;
?>
</body>
</html>
4

2 回答 2

2

(已测试)

您的表单未显示的原因是因为这两行:

1)这个结尾缺少右括号)

$password = md5(md5("Ji5t63s".password."v5h2ih47");

应该:

$password = md5(md5("Ji5t63s".password."v5h2ih47"));

2) -<a href="./member.php">问题是(未转义的)双引号或使用单引号。

您现有的线路:

echo "You have been logged in as <b>$dbuser</b>. <a href="./member.php">Click here</a> to go to the member page.";

应该:

echo "You have been logged in as <b>$dbuser</b>. <a href='./member.php'>Click here</a> to go to the member page.";

或逃避他们\"

echo "You have been logged in as <b>$dbuser</b>. <a href=\"./member.php\">Click here</a> to go to the member page.";

现在就其余部分的功能(带有包含文件的代码)而言,这是我无法控制的。你问为什么你的表格没有出现。

于 2013-10-05T20:02:47.277 回答
-2

Please don't have any whitespace characters before your session_start() .

Instead of:

    <?php
session_start(); ?>

please make it:

<?php
session_start();?>

The session needs to be started before you output anything to the browser. Please remember PHP is an interpreter, and therefore is executed by each line.

于 2013-10-05T17:43:18.657 回答