I want to check if the form was filled out correctly but the alert appears after I load the page. I guess a site refresh is submitting the login button.
I try to check the incoming data and if they are wrong, it should show an alert.
<?php
$alert = "";
if ($_POST['username'] == null || $_POST['password'] == null){
$alert = "Please fill in all fields!";
}
if ($alert){
echo $alert;
}
?>
<form method="POST" action=""> <!-- reloads this page -->
<input type="text" name="username"/>
<input type="password" name="password"/>
<button type="submit" name="login">Login</button>
</form>
If I open the page, the alert appears instantly. How should I do the check, that the alert does not appear after the first load.