The following PHP code echoes error before entering mistaken password and gives – Notice: Undefined index: password
<?php
//Specify password here
$pass='pass';
if($_POST['password']!=$pass)
{
echo ("<div class='errmg'>Error</div>");
}
else
{
header( 'Location: admin.php' ) ;
}
?>
Below I’ve the following HTML
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Enter password:
<input name="password" type="password">
<input name="send" type="submit" value="Log in!">
</form>
Please help me to repair these errors and make this login-redirect better
If you haven’t submitted the form,
$_POSTis empty, so there’s no$_POST['password'], just as the error says. Always check whether variables that may or may not be set exist before using them: