我正在尝试使用PHP验证用户的登录凭据。当用户输入错误的密码,或者用户根本不存在时,代码会重定向到包含相应错误消息的空白页。
我想要悬停的是,当我更改注册字段以验证凭据时,它必须输出错误消息以及登录区域。例如,当用户没有填写所有字段时,他将看到一个新页面,相应的错误消息和下面的登录区域。
我查看了我的编码,但我无法解读为什么注册会在空白页面上显示我的错误消息,而不会在其下面显示登录区域。
这是我的登录
$username = $_POST['username'];
$password = $_POST['password'];
if ($username&&$password)
{
$host_name = 'localhost';
$db_user ='root';
$db_pass = '';
$db_name = 'login';
/* Connect to MySQL */
$con = mysql_connect("$host_name","$db_user","$db_pass") or die ("Couldn't connect!");
$db = mysql_select_db("$db_name") or die ("Couldn't connect to 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'];
}
/*Check to see if they match! */
if ($username==$dbusername&&$password==$dbpassword)
{
echo "You're in! <a href='member.php'> Click</a> here to enter the member page";
}
else
echo "Incorrect password";
}
else
die("That user doesn't exist!");
}
else
die("Please enter username and/or password!");
?>
第二个代码是我的注册页面,它在同一页面上显示我的错误消息
<?php
echo "<h1>Register</h1>";
if (isset($_POST['submit']))
{
/* Form data */
$fullname = strip_tags($_POST['fullname']);
$username = strip_tags($_POST['username']);
$password = md5(strip_tags($_POST['password']));
$repeatpassword = md5(strip_tags($_POST['repeatpassword']));
$date = date("Y-m-d");
}
if ($submit)
/*check for existance */
if ($fullname&&$username&&$password&$repeatpassword)
{
}
else
echo "<font color='red'><b>Please fill in all fields!</font></b>";
?>