Login or Signup with jQuery and PHP

Jquery dom is very powerful to manipulate dom elements in your web application. In this tutorial i will show you how to use jquery dom in login or signup form example.

in the pictures below you should notice the differences. When “I have an account” is selected, it wants you to login by typing your password and click Submit button. In another side if “I am new” is selected the application wants you to signup by typing your new password and click Signup button.
jquery dom jquery dom

Using PHP and Jquery especially jquery dom, it is easy to be achieved.

index.php

<html>
  <head>
  	  <script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
      <script type="text/javascript">
           $(document).ready(function(){
                $("#login").click(function(){
                   $("#newpassword").val("");
                   $("#signup_block").hide();
                   $("#login_block").show();
                });

                $("#signup").click(function(){
                   $("#password").val("");
                   $("#login_block").hide();
                   $("#signup_block").show();
                });
           });
      </script>
  </head>
  <body>
        <form type="post" method="login.php">
            <div>
                <label>Email</label> <br/>
                <input type="text" name="email"/><br />
                <input type="radio" name="choose" id="login" checked="checked"/> I have an account <br />
                <input type="radio" name="choose" id="signup"/> I am new!<br />
                </div>

                <div id="login_block">
                <label>Password</label><br />
                <input type="password" name="password" id="password"/><br/>
                <input type="submit" value=" Login "/> 
                </div>

                <div id="signup_block" style="display:none">
                <label>Choose password</label><br/>
                <input type="password" name="newpassword" id="newpassword" /><br/>
                <input type="submit" value=" Signup "/>
            </div>
        </form>
  </body>
</html>

login.php

<?php
if($_POST){
 $email = $_POST['email'];
 $password = $_POST['password'];
 $newpassword = $_POST['newpassword'];

  if($_POST['password'] && $_POST['email']){
    $sql=mysql_query("SQl select statement");
    echo "Login success";
  }
  else if($_POST['newpassword'] && $_POST['email']){
    $sql=mysql_query("SQl Insert values statement");
    echo "Registration Success";
  }

}
?>
Advertisements

2 thoughts on “Login or Signup with jQuery and PHP

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s