I have the following php code, which works on its own. However, when using it AJAX it returns an empty response.
PHP login code:
<?php
session_start();
include_once 'resources/database.php';
if(isset($_POST['m_login_signin_submit'])) {
$email = trim($_POST['email']);
$user_password = trim($_POST['password']);
$password = MD5($user_password);
try {
$stmt = $db->prepare("SELECT * FROM users WHERE email=:email");
$stmt->execute(array(':email' => $email));
$row = $stmt->fetch(PDO::FETCH_ASSOC);
$count = $stmt->rowCount();
if($row['password']==$password) {
echo '1';
$_SESSION['user_session'] = $row['id'];
} else {
echo 'You do not matter.';
}
} catch (PDOException $ex) {
echo $ex->getMessage();
}
}
AJAX Code:
$(document).ready(function () {
/* validation */
$("#login-form").validate({
submitHandler: submitForm
});
function submitForm() {
var email = $('#email').val();
var password = $('#password').val();
console.log(data);
$.ajax({
type: 'POST',
dataType: 'text',
url: 'partials/processLogin.php',
data: {
email:email,
password:password
},
success: function (response) {
console.log("Checking success.");
console.log(response);
},
error: function () {
console.log("error");
}
});
return false;
}
});
In console, all the values pass correctly and it returns success but the value is empty. Any help is greatly appreciated.
Thank you