I'm having issues when submitting the form. Whenever i submit the form, it refreshes the page and does not perform any action whether the username and password are true or not. However, if i don't use ajax and simply use the PHP it works like a charm.
I'm new to ajax so i'm not able to figure out what's the issue here
Here's the php part:
include('AdminPanel/connect.php');
session_start();
$email = $_POST['txt_email'];
$password = $_POST['txt_pass'];
$info = mysqli_query($con,"select count(*) from signup where Email = '$email'
and Password = '$password'");
$row = mysqli_fetch_array($info);
if ($row[0] > 0)
{
$_SESSION['txt_email']=$email;
echo "success";
}
else
{
echo "Email or Password is incorrect";
}
?>
Ajax part:
$(document).ready(function() {
$('#lgnfrmmm').submit(function(e) {
e.preventDefault();
$.ajax({
type: "POST",
url: 'query.php',
data: $(this).serialize(),
success: function(data)
{
if (data === 'success') {
window.location = 'index.php';
}
else {
$('#msg').html(data);
}
}
});
});
});
HTML:
<form action="#" method="post" id="lgnfrmmm">
<input class="log_email_field" placeholder="Email" type"text"
name="txt_email" id="txt_email" autocomplete="off"/>
<input class="log_pass_field" placeholder="Password" type="password"
name="txt_pass" id="txt_pass" />
<div class="panel22 pink">
<button class="btnlogin" name="btn_log" type="submit">Log-in</button>
</div>
</form>
<p id="msg"></p>