我在一个网站上工作,我从数据库中获取记录以匹配用户输入,如果数据与数据库中的详细信息不匹配,它必须显示一个 javascript 警报框。但问题是 javascript 框也显示在身体负载上。以下是我的代码:
//Storing the value of form's username and password into PHP variables
$username = $_POST['username'];
$password = $_POST['password'];
//This query is to check whether ther user has provided valid details
$query = mysql_query("Select * from accounts where username='$username' and password='$password'");
$status = mysql_num_rows($query);
/**Now checking whether the number of rows returned by database are greater than 0 to verify the login
if number of rows are greater than zero we will redirect the user to index page with a session variable**/
if($status >0)
{
$_SESSION['username'] = $username;
?>
<meta http-equiv="refresh" content="0;url=index.php">
<?}
else
{?>
<script language="javascript">
alert('UserName or Password does not match. Please try again');
</script>
<?}?>