I have a PHP script which is supposed to check my database where the user email that is input exists. I've got everything set up so that the script runs when the form is submitted but I think there must be something wrong with how my form is set up. It doesn't seem to recognize that a row exists. I've put in an email address I know for a fact exists; however, it doesn't seem to find it.
app.js
$(document).ready(function() {
$("submit").click(function() {
alert("This was a test.");
$.ajax({
type: "POST",
url: "main_login.php",
success: function(data) {
alert(data);
$(".message").text(data);
}
});
});
});
main_login.php
<?php
$conn = new mysqli('localhost', 'user', 'pass!', 'db');
mysqli_set_charset($conn, 'utf8mb4');
$check = "SELECT * FROM users WHERE email = '$_POST[email]'";
$results = mysqli_query($conn, $check);
$data = mysqli_fetch_array($results, MYSQLI_NUM);
if($data == 1) {
echo "Login successful";
} else {
echo "This account does not exist";
}
$conn->close();
?>
login.php
<div class="container login">
<div class="panel panel-default login-panel">
<div class="panel-heading">span class="log-h1">Sign-in</span>
</div>
<div class="panel-body">
<form name="loginform" action="login.php" method="post">
<div class="form-group">
<label for="username">Email</label>
<input type="email" class="form-control"
name="email" id="email" placeholder="Email address">
</div>
<div class="form-group" style="float: right;">
<input type="submit" class="btn btn-primary" name="Submit"
value="Sign-in">
</div>
</form>
<span class='message'></span>
</div>
</div>
</div>
Again, everything works except for the verification that the email address I provided exists. I doesn't think it does no matter what I do.