How to prevent blank page to be shown using PHP?

I am beginner php student. I have a code for login that check if the username and password are correct.
everything is OK, but if the username or password are incorrect, the code generate error message then show blank page. How can I prevent this blank page to be shown?

<?php $username = $_POST['u']; $password = $_POST['p']; $username = stripcslashes($username); $password = stripcslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); mysql_connect("localhost","root","0598985166sallam"); mysql_select_db("project"); $result = mysql_query("select * from employees where username = '$username' and password = '$password' ") or die("faild"); $row = mysql_fetch_array($result); if($row['username'] == $username && $row['password']==$password) { $NoOFLetter = strlen($username); $result = substr($username, $NoOFLetter-3, $NoOFLetter); if($result == "doc"){header('Location: tabeeb.html'); exit;} if($result == "sec"){header('Location: sec.html'); exit;}} else{ } // what to add here? ?>

I tried this code

echo '<script language="javascript">';
      echo 'alert("Error in Username or Password!")';
      echo '</script>';

but the blank page also appear.

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!