I am writing a simple login script in PHP with a form. But can't get it to work. There is probably something wrong with my AJAX. When i click the submit button it doesn't do anything.
This is my login HTML form:
<form id="login_form">
<input type="text" class="input_field" name="username" id="username" value="gebruikersnaam" onclick="if(value=='gebruikersnaam'){ this.value='' }"/>
<input type="password" class="input_field" name="password" id="password"/>
<input type="submit" class="login_button" id="login_button" value="Ga door"/>
</form>
This is my AJAX:
$(document).ready(function(){
$("#login_form").submit(function() {
$.ajax({
type: "POST",
url: 'php/login_check.php',
data: $("#login_form").serialize(), // serializes the form's elements.
succes: function(logincheck) {
if (logincheck == 'true') {alert ("Succes");}
else {alert ("Failed");}
}
});
return false; // avoid to execute the actual submit of the form.
});
});
This is my PHP:
<?php
session_start();
include 'config.php';
$username = $_POST['username'];
$password = $_POST['password'];
//Check for credentials
$Credentials_Query = mysqli_query ($mysqli, "SELECT * FROM Registered_Users WHERE Username='$username' AND password='$password'");
$num_row = mysqli_num_rows($Credentials_Query);
$row=mysqli_fetch_array($Credentials_Query);
if( $num_row >= 1 ) {
echo 'true';
$_SESSION['username_session']=$row['Username'];
}
else {
echo 'false';
}
?>
I know this is really basic stuff. Still I can't get it to work. Don't know what I'm missing...?