Make Login Form With JQuery v2 PHP Script

Make Login Form With JQuery v2 PHP Script

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.

Username: tutorial
Password: admin
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

 
 

<script type="text/javascript">
$(document).ready(function() {
$("#submit").click(function() {
var username = $("#username").val();      
      var password = $("#password").val();
      if(username=='' || password=='' ){
      alert("Please enter the username and password");
      }
      else {            
$.ajax({
type: "POST",
url: "login_function.php",
data: "username="+ username + "&password=" + password ,

      beforeSend: function()
            {
                  $('#display_query').html('Loading....');
            },
            success: function(response)
            {
                  $("#display_query").fadeIn(2000).html(response);

                  document.getElementById('username').value='';
       document.getElementById('password').value='';

            }
});
}            
return false;
      });

});
</script>

 

For PHP Code


 

<!---
Welcome to the Sourcecodester.com
For more tutorials, kindly visit our website:

https://www.sourcecodester.com/
-->
<?php
$db = mysql_connect('localhost','root','') or die ("Unable to connect to Database Server.");
mysql_select_db ('login_jquery', $db) or die ("Could not select database.");

if(isset($_POST['username']))
{
$username=$_POST['username'];
$password=$_POST['password'];
$query = mysql_query("select * from user where username='$username' and password='$password' ")or die(mysql_error());                  
            $data = mysql_fetch_row($query);
            if($data){      
            echo '<a id="sucess"><img src="image/success.png"></a>';}
            else {
            echo '<a id="error"><img src="image/invalid.png"></a>';}

}?>

 

For CSS Code


 

<style type="text/css">
#display_query {
      display:none;
      border-radius:3px;
      margin-bottom:4px;
}

table {
      width:300px;
      float:left;
}

label {
      color:blue;
      font-size:20px;
      font-weight:bold;
}

.text_style {
      font-size:18px;
      text-indent:5px;
}

.btn_style {
      font-size:18px;
      border:3px groove #CCC;
      border-radius:7px;
      width:100px;
      font-weight:bold;
}
</style>

 

For HTML Code


 

<form method="post" name="form" action="">
<table cellspacing="4" cellpadding="4">
      <tr style="background-color:#000000;">
            <td colspan="2" align="center">
                  <h2 style="color:#FFFFFF;">Enter the details below...</h2>
            </td>
      </tr>
      <tr>
            <td>
                  <label>Username</label>
            </td>
            <td>
                  <input name="username" class="text_style" placeholder="Username..." type="text" id="username" />
            </td>
      </tr>
      <tr>
            <td>
                  <label>Password</label>
            </td>
            <td>
                  <input name="password" class="text_style" placeholder="Password..." type="password" id="password" />
            </td>
      </tr>
      <tr>
            <td colspan="2" align="center">
                  <input type="submit" class="btn_style" name="submit" value="Submit" id="submit" />
            </td>
      </tr>
      <tr>
            <td colspan="2">
                  <a align="center" id="display_query"></a>
            </td>
      </tr>
</table>
</form>

<table style="margin-left:100px;">
      <tr>
            <td>
                  <label>Database Name</label>
            </td>
            <td>
                  <span style="color:red;">login_jquery</span>
            </td>
      </tr>
      <tr>
            <td>
                  <label>Username</label>
            </td>
            <td>
                  <span style="color:red;">tutorial</span>
            </td>
      </tr>
      <tr>
            <td>
                  <label>Password</label>
            </td>
            <td>
                  <span style="color:red;">admin</span>
            </td>
      </tr>
</table>

<a href="https://www.sourcecodester.com" style="float:right;">
      <h3>
            Sourcecodester
      </h3>
</a>

 

 

 

Comments

Popular posts from this blog

Motos Android Mame Game Download

StatusNet Micro Blog PHP Script Free Download

1941 Counter Attack (Japan) Windows Game Download