jQuery AJAX Tutorial Pt2
May
13
Heres Part 2 of the jQuery AJAX login tutorial. If you haven’t already, i suggest you read part 1 located here.
We are going to start writing the PHP code to process the form. This is fairly basic stuff, using $_POST to get the values from the form, then checking them against pre-assigned values, if they match, then echo approved, if they don’t then echo denied.
-
<?php
-
-
if($_POST[’submit’]){
-
-
-
$username = $_POST[‘username’];
-
$password = $_POST[‘password’];
-
-
// Here you would put your validation, checking existing database records.
-
-
if($username == panzer && $password == query7){
-
-
echo ‘Logged in’;
-
-
//Insert your cookie setting code here
-
-
} else {
-
-
echo ‘Denied’;
-
-
}
-
-
} else {
-
-
echo "Form not submitted";
-
-
}
-
?>
So at the end of this stage, you will have an HTML form set up and this PHP file. You can enter the username Panzer and the password of query7 into the form and it will return Logged in.
Next tutorial, the fun part, the AJAX!









