jQuery AJAX Tutorial Pt2

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.

  1. <?php
  2.  
  3. if($_POST[’submit’]){
  4.  
  5.  
  6. $username = $_POST[‘username’];
  7. $password = $_POST[‘password’];
  8.  
  9. // Here you would put your validation, checking existing database records.
  10.  
  11. if($username == panzer && $password == query7){
  12.  
  13. echo ‘Logged in’;
  14.  
  15. //Insert your cookie setting code here
  16.  
  17. } else {
  18.  
  19. echo ‘Denied’;
  20.  
  21. }
  22.  
  23. } else {
  24.  
  25. echo "Form not submitted";
  26.  
  27. }
  28. ?>

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!

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • StumbleUpon
  • bodytext
  • description
  • Slashdot
  • Technorati
  • Sphinn
  • del.icio.us
  • Facebook
  • Google
Filed under: Uncategorized, ajax, code, jquery, php, tutorial, , ,

Leave a Reply