Hello I have created a script for login using ajax method I tried but this is not working for me getting unsuccessful can you please let me know why i am unable to work with this
function login() {
var username = document.getElementById('username').value;
var pass = document.getElementById('pass').value;
if(username == '' && pass == '') {
alert('Fields could not be left empty');
} else {
$.ajax({
type : "POST",
url : "includes/register.php",
data : "command=login&username="+username+"&password="+pass,
datatype : "json",
success : function(data) {
if (data.status == 200) {
alert('Successfull');
var return_data = data.responseText;
document.getElementById('messagearea').innerHTML = return_data;
} else {
alert('Unsuccessful');
}
}
});
}
}
it should run alert successful but I am getting alert('Unsuccessful') it means that status is not equal 200 can anyone help me out with that
Here is my php code
if(isset($_POST['command']) && $_POST['command'] == 'login') {
$username = $_POST['username'];
$pass = $_POST['pass'];
$password = md5($pass);
$check = mysqli_query($connection, "SELECT * FROM users WHERE username = '$username'");
$result = mysqli_num_rows($check);
if($result != 1) {
echo "<div class='message'>Response Successful</div>";
} else {
echo "<div class='message'>Username/Password did not matched</div>";
}
}