How To Make Login Form With JQuery In PHP

Submitted by: 
Language: 
Visitors have accessed this post 3103 times.

Good Day!!!

Related Code: How To Make Register Form with JQuery Validation

In this tutorial, we are going to learn How To Make Login Form With JQuery In PHP. This is simple project and it consists username and password.

  1. Username
    • tutorial
  2. Password
    • admin
  3. Database Name
    • login_jquery

You can use it to your Website or System. Download the source code and try it. Enjoy Coding...

Directions:

For JQuery Code

  1. <script type="text/javascript">
  2. $(document).ready(function() {
  3. $("#submit").click(function() {
  4. var username = $("#username").val();
  5. var password = $("#password").val();
  6. if(username=='' || password=='' ){
  7. alert("Please enter the username and password");
  8. }
  9. else {
  10. $.ajax({
  11. type: "POST",
  12. url: "login_function.php",
  13. data: "username="+ username + "&password=" + password ,
  14.  
  15. beforeSend: function()
  16. {
  17. $('#display_query').html('Loading....');
  18. },
  19. success: function(response)
  20. {
  21. $("#display_query").fadeIn(2000).html(response);
  22.  
  23. document.getElementById('username').value='';
  24. document.getElementById('password').value='';
  25.  
  26. }
  27. });
  28. }
  29. return false;
  30. });
  31.  
  32. });
  33. </script>

For PHP Code

  1. <!---
  2. Welcome to the Sourcecodester.com
  3. For more tutorials, kindly visit our website:
  4.  
  5. https://www.sourcecodester.com/
  6. -->
  7. <?php
  8. $db = mysql_connect('localhost','root','') or die ("Unable to connect to Database Server.");
  9. mysql_select_db ('login_jquery', $db) or die ("Could not select database.");
  10.  
  11. if(isset($_POST['username']))
  12. {
  13. $username=$_POST['username'];
  14. $password=$_POST['password'];
  15. $query = mysql_query("select * from user where username='$username' and password='$password' ")or die(mysql_error());
  16. $data = mysql_fetch_row($query);
  17. if($data){
  18. echo '<div id="sucess"><img src="image/success.png"></div>';}
  19. else {
  20. echo '<div id="error"><img src="image/invalid.png"></div>';}
  21.  
  22. }?>

For CSS Code

  1. <style type="text/css">
  2. #display_query {
  3. display:none;
  4. border-radius:3px;
  5. margin-bottom:4px;
  6. }
  7.  
  8. table {
  9. width:300px;
  10. float:left;
  11. }
  12.  
  13. label {
  14. color:blue;
  15. font-size:20px;
  16. font-weight:bold;
  17. }
  18.  
  19. .text_style {
  20. font-size:18px;
  21. text-indent:5px;
  22. }
  23.  
  24. .btn_style {
  25. font-size:18px;
  26. border:3px groove #CCC;
  27. border-radius:7px;
  28. width:100px;
  29. font-weight:bold;
  30. }
  31. </style>

For HTML Code

  1. <form method="post" name="form" action="">
  2. <table cellspacing="4" cellpadding="4">
  3. <tr style="background-color:#000000;">
  4. <td colspan="2" align="center">
  5. <h2 style="color:#FFFFFF;">Enter the details below...</h2>
  6. </td>
  7. </tr>
  8. <tr>
  9. <td>
  10. <label>Username</label>
  11. </td>
  12. <td>
  13. <input name="username" class="text_style" placeholder="Username..." type="text" id="username" />
  14. </td>
  15. </tr>
  16. <tr>
  17. <td>
  18. <label>Password</label>
  19. </td>
  20. <td>
  21. <input name="password" class="text_style" placeholder="Password..." type="password" id="password" />
  22. </td>
  23. </tr>
  24. <tr>
  25. <td colspan="2" align="center">
  26. <input type="submit" class="btn_style" name="submit" value="Submit" id="submit" />
  27. </td>
  28. </tr>
  29. <tr>
  30. <td colspan="2">
  31. <div align="center" id="display_query"></div>
  32. </td>
  33. </tr>
  34. </form>
  35.  
  36. <table style="margin-left:100px;">
  37. <tr>
  38. <td>
  39. <label>Database Name</label>
  40. </td>
  41. <td>
  42. <span style="color:red;">login_jquery</span>
  43. </td>
  44. </tr>
  45. <tr>
  46. <td>
  47. <label>Username</label>
  48. </td>
  49. <td>
  50. <span style="color:red;">tutorial</span>
  51. </td>
  52. </tr>
  53. <tr>
  54. <td>
  55. <label>Password</label>
  56. </td>
  57. <td>
  58. <span style="color:red;">admin</span>
  59. </td>
  60. </tr>
  61.  
  62. <a href="https://www.sourcecodester.com" style="float:right;">
  63. <h3>
  64. Sourcecodester
  65. </h3>
  66. </a>

Related Code: How To Make Register Form with JQuery Validation

So what can you say about this work? Share your thoughts in the comment section below or email me at [email protected]. Practice Coding. Thank you.


Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • You may insert videos with [video:URL]
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3> <iframe> [video]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.