I have developed a login page in PHP. I am using PHP code to validate that username and password are not empty. Javascript alert box is popped out on error and page is navigating back to login page. Now suppose if user enters username and does not enter password and clicks on login, password is empty box is displayed and now user I want user to navigate back to login page with username populated with previous value entered by him. I am beginner to PHP, and not getting idea on how to do this. This is my code
if($myusername == null){
echo '<script language="javascript">';
echo 'alert("Username cannot be empty")';
echo '</script>';
echo "<meta http-equiv='refresh' content='1; URL=main_login.php'>";
exit();
}
if($mypassword == null){
echo '<script language="javascript">';
echo 'alert("Password cannot be empty")';
echo '</script>';
echo "<meta http-equiv='refresh' content='1; URL=main_login.php'>";
exit();
}