我是一名初学者,正在学习PHP编程。我想在login.php页面中,如果用户输入了错误的用户名或密码,则显示错误消息。下面是两个页面的代码。login.php页面会提交用户名和密码到check.php页面。如果用户名和密码正确,则会重定向到xyz.php页面,否则会返回到登录页。
login.php//登录页面
<form name="login" enctype="multipart/form-data" action="checkpage.php" method="post">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<th>Username</th>
<td><input type="text" name="username" value="sandeep" onfocus="this.value=''" class="login-inp" /></td>
</tr>
<tr>
<th>Password</th>
<td><input type="password" name="password" class="login-inp" /></td>
</tr>
<tr>
<th></th>
<td valign="top"><input type="checkbox" class="checkbox-size" id="login-check" /><label for="login-check">Remember me</label></td>
</tr>
<tr>
<th></th>
<td><input type="submit" class="submit-login" /></td>
</tr>
<tr><th></th><td>w want to display error message here..</td></tr>
</table></form>
checkpage.php //连接页面
<?php
session_start();
//connecting to db
$username=$_POST['username'];
$pwd=$_POST['password'];
$q="select *from xyz where username='$username' AND password='$pwd'";
$qry=mysql_query($q);
if(mysql_num_rows($qry)>0)
{
$_SESSION['username']=$username;
echo "<script>window.open('xyz.php','_self')</script>";
}
else{
header("location:login.php");
}
?>
上述代码正常工作,但我想显示错误消息,怎么办?请指导我。