我一直在尝试通过 PHP 制作登录系统。当我尝试运行它时,所有代码($errors as $error)
都显示在实际网页上。我一直在尝试测试它几个小时。
注意:当我将 更改为>
时<
,它可以正常工作,if(count($errors) > 0){
但这使得即使密码/用户名出现错误,他们仍然可以按 Enter 键。
请提供任何帮助!提供了代码。
<?
mysql_pconnect('localhost', 'root', '');
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Login</title>
</head>
<body>
<?php
if(!$_POST['submit']) {
?>
<form action="index.php" method="post">
<table border="1">
<tr>
<td>
Username:
</td>
<td>
<input type="text" name="username" />
</td>
</tr>
<tr>
<td>
Password:
</td>
<td>
<input type="text" name="password" />
</td>
</tr>
<tr>
<td>
Retype Password:
</td>
<td>
<input type="text" name="passwordconf" />
</td>
</tr>
<tr>
<td>
Email Address:
</td>
<td>
<input type="text" name="email" />
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="Create User" name="submit" />
</td>
</tr>
</table>
</form>
<?php
} else {
$username = $_POST['username'];
$password = $_POST['password'];
$passwordconf = $_POST ['passwordconf'];
$email = $_POST ['email'];
$errors = array();
if(!$username) {
$errors[1] = "Please enter a username.";
}
if(!$password) {
$errors[2] = "Please enter a password.";
}
if(!$passwordconf) {
$errors[3] = "Please retype password.";
}
if(!$email) {
$errors[4] = "Please enter an email address.";
}
if($password != $passwordconf) {
$errors[5] = "Passwords do not match.";
}
if(count($errors) > 0){
foreach($errors as $error) {
echo "$error<br>";
}
} else {
mysql_query("INSERT INTO 'users' . 'user_info'
('username', 'password', 'email', 'user_admin_level')
VALUES ('".$username."', '".md5($password)."', '".$email."', '1');");
}
}
?>
</body>
</html>