0

所以这次我决定使用网络编程语言。我一直很喜欢 PHP 的工作方式,所以我开始学习它。我已经开始制作登录页面,但我只是不知道它有什么问题。如果我使用符号没有错误。我什至不认为表格已处理。这是在同一页面上处理表单的正确方法吗?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<?php
session_start();
include("includes/connect.php");

if(isset($_SESSION['uid'])){
    header('Location:member.php');
}

if(isset($_POST['submit'])){
    $error = array();

    //username
    if(empty($_POST['username'])){
        $error[] = 'You cant have no username can you';
    }else if(ctype_alnum($_POST['username'])){
        $username = $_POST['username'];
    }else{
        $error[] = 'Username cannot contain symbols';
    }

    //password
    if(empty($_POST['password'])){
        $error[] = 'YOU NEED A PASSWORD';
    }else{
        $password =  sha1(mysql_real_escape_string($_POST['password']));
    }

    //error
    if(empty($error)){
        $result = mysql_query("SELECT * FROM user_info WHERE username='$username' AND password='$password'") or die(mysql_error());
        if(mysql_num_rows($result)==0){
            $error_message='Username or Password wrong';
        }else{
            $_SESSION['username'] = $username;
            $_SESSION['user_id'] = mysql_result($result, 0, 'user_id');
        }
    }else{
        foreach($error as $key => $values) {
            $error_message.= "$values";
        }
    }
}


?>

<html>
<head>
    <title>Login :)</title>
</head>
<body>
<div style="background-color:#A0A0A0" align="center">
<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
    <h3>Login</h3>
    <div>
        <label for="username">Username:</label>
        <input type="text" name="username" maxlength="10"/>
    </div>
    <div>
        <label for="password">Password:</label>
        <input type="password" name="password" maxlength="20"/>
    </div>
    <div>
        <input type="submit" name="submit "value="Login"/>
    </div>
</form>
<?php echo $error_message; ?>
</div>
</body
</html>
4

1 回答 1

3

你的身体标签没有关闭你忘了>

</body>

并删除提交按钮名称中的空格:)

于 2012-04-14T17:56:08.460 回答