I'm creating a website for my assignment, and I want the page to not refresh after I entered the wrong password and username combination.
I'm using both PHP and javascript, and I don't use MYSQL to store the login information
This is my PHP Script
<?php
if (isset($_POST['login']) && !empty($_POST['username'])
&& !empty($_POST['password'])) {
if ($_POST['username'] == 'admin' &&
$_POST['password'] == 'admin') {
$_SESSION['username'] = 'admin';
header ('Location: mainPage.php');
}else {
/*What should I include here? */
}
}?>
This is my Javascript code
<script>function pasuser(form) {
if (form.username.value=="admin") {
if (form.password.value=="admin") {
}
else {
document.getElementById("loginFail").innerHTML = '<div class="w3-container w3-section w3-red"> <span onclick="this.parentElement.style.display=\'none\'" class="w3-closebtn">×</span><h3>WRONG PASSWORD</h3><p>You need to enter the correct password.</p></div>';
}
}
else{
document.getElementById("loginFail").innerHTML = '<div class="w3-container w3-section w3-red"> <span onclick="this.parentElement.style.display=\'none\'" class="w3-closebtn">×</span><h3>WRONG USERNAME</h3><p>You need to enter the correct username.</p></div>';
}</script>
and the form
<html><form class="w3-container w3-card-8 w3-margin-16" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" >
<h2 class="w3-text-blue">LOGIN PAGE</h2>
<p>
<label class="w3-text-blue"><b>Username</b></label>
<input class="w3-input" name="username" type="text" placeholder="Enter your username here"></p>
<p>
<label class="w3-text-blue"><b>Password</b></label>
<input class="w3-input" name="password" type="password" placeholder="Enter your password here"></p>
<p>
<button type='submit' class="w3-btn w3-blue" type="button" name="login" value="LOGIN" onclick="pasuser(form)">LOGIN</button></p>
<span id="loginFail">
</form></html>
Basically I want the javascript function of displaying a W3.CSS card alert when the login is not success without having the page reloads itself. If the page reloads itself, the card will dissapear