php - How to validate the username and password and also the selected role from database using javascript/ajax or any other validation formates -


hi want indicate user name wrong ur password wrong ur role wrong ., using validations ajax/javascript or other..

index.php

<html>    <head>    </head>    <body>       <style>          body {             width:400px;              height:auto;              margin: 0 auto;              padding-top:20px;          }          body {              text-decoration:none;              color:#0099cc;          }          .border{              border:#999999;              border-style:solid;              border-width:thin;          }       </style>         <?php             include('connect.php');         ?>       <table width="350" class="border" >          <form id="form1" name="form1" method="post" action="login.php" onsubmit="return validate()">             <tr>                <td width="112">&nbsp;</td>                <td colspan="2"> <strong>login</strong></td>                <td width="22">&nbsp;</td>             </tr>             <tr>                <td height="35">                   <div align="right">user name : </div>                </td>                <td colspan="2"><label>                   <input type="text" name="name" id="name" /></label>                </td>                <td>&nbsp;</td>             </tr>             <tr>                <td>                   <div align="right">password : </div>                </td>                <td colspan="2"><input type="password" name="password" id="password" /></td>                <td>&nbsp;</td>             </tr>             <tr>                <td>                   <div align="right">select role : </div>                </td>                <td colspan="2">                   <!--  <input type="radio" checked="checked" name="title" value="member" id="member" /> member</label>                      <label for="admin"> <input type="radio" name="title" value="admin" id="admin" /> admin</label> -->                   <label>                      <select name="member" id="member">                         <option title="title" value="member"> member                         <option title="title" value="admin"> admin                      </select>                   </label>                </td>                <td>&nbsp;</td>             </tr>             <tr>                <td>&nbsp;</td>                <td width="69"><label>                   <input type="submit" name="submit" value="login" id="add" /></label>                </td>                <td width="127"><label>                   <input type="reset" name="reset" value="reset" /></label>                </td>                <td>&nbsp;</td>             </tr>             <tr>                <td>&nbsp;</td>                <td><a href="register.php">register ?</a> </td>                <td><a href="forget_password.php">forget password?</a> </td>                <td>&nbsp;</td>             </tr>          </form>       </table>       <script>          function validate()          {             if( document.form1.name.value == "" )             {                 alert( "please provide name!" );                 document.form1.name.focus() ;                 return false;             }             if( document.form1.password.value == "" )             {                 alert( "please provide password!" );                 document.form1.password.focus() ;                 return false;             }          }       </script>    </body> </html> 

login.php

<?php     session_start();     include('connect.php');     $name = $_post['name'];     $password = $_post['password'];     $role = $_post['member'];     $sql = "select * login_register name = '$name'      , password = '$password' , role = '$role'";     $retain = mysql_query($sql, $con);     // mysql_num_row counting table row     $count=mysql_num_rows($retain);     $row=mysql_fetch_array($retain);      if($count == 1)     {         if ( $role == "admin")         {             $_session['adminuser']=$_post['name'];             header("location:admin_home.php");         }         else  if ( $role == "member")         {             header("location:member_home.php");             $_session['user']=$_post['name'];         }     }     else      {         echo  "<a href='index.php'>click here login   </a>";     } ?> 

i want indicate user name wrong ur password wrong ur role wrong ., using validations ajax/javascript or other..

here sample jquery code. may it'll you. expect response data in json format & according response data value rest of execution.

$.ajax({     type    : "post",     data    : { username: "user name", password: "user password", role:"your role" },     url     : 'some.php',     datatype: 'json',     success : function(response) {                             console.log( "response data: " + response );                       } }); 

for more : http://api.jquery.com/jquery.ajax/


Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -