I don't know what is wrong here. preventDefault should stop the form from submitting but it still proceeds to. I have an ajax call where it verifies if user is valid. If not, prevent from submitting. Else, proceed to login and home page.
Form
<form id="signIn" method="post" action="processForms.php">
<table cellspacing="10">
<tr id="errorSignIn" hidden="hidden">
<td class="centerItem errorMessage" colspan="3">
Incorrect Username and/or Password
</td>
</tr>
<tr>
<td><input type="text" id="username" name="username" autocomplete="off" autofocus required placeholder="Username..."></td>
<td><input type="password" id="password" name="password" autocomplete="off" required placeholder="Password..."></td>
<td><input type="submit" name="processButton" class="signIn" value="Sign-in" ></td>
</tr>
</table>
</form>
Javascript
$('#signIn').submit ( function (e) {
var username = $('#username').val();
var password = $('#password').val();
var dataString = "username=" + username + "&password=" + password;
$.ajax( {
type: "POST",
url: "ajaxCheck.php",
data: dataString,
cache: false,
success: function (result) {
if (!result) {
$('#errorSignIn').removeAttr('hidden');
e.preventDefault();
return false;
}
}
});
});
ajaxCheck.php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
$dbConnection = mysqli_connect('localhost','root','','onboard');
$query = "SELECT * FROM account WHERE username='$username' AND password='$password'";
$result = mysqli_query($dbConnection,$query);
$count = mysqli_num_rows($result);
if ($count == 1) { echo true; }
else { echo false; }