title: How to validate the username and password and also the selected role from database using javascript/ajax or any other validation formats
body: <p>I just want to indicate user your name is wrong ur password is wrong ur role is wrong .,
  using any validations like ajax/javascript or any other..</p>
  
  <p>index.php</p>
  
  <pre><code>&lt;html&gt;
     &lt;head&gt;
     &lt;/head&gt;
     &lt;body&gt;
        &lt;style&gt;
           body {
              width:400px;
               height:auto;
               margin: 0 auto;
               padding-top:20px;
           }
           body a {
               text-decoration:none;
               color:#0099CC;
           }
           .border{
               border:#999999;
               border-style:solid;
               border-width:thin;
           }
        &lt;/style&gt;
          &lt;?php
              include('connect.php');
          ?&gt;
        &lt;table width="350" class="border" &gt;
           &lt;form id="form1" name="form1" method="post" action="login.php" onSubmit="return validate()"&gt;
              &lt;tr&gt;
                 &lt;td width="112"&gt;&amp;nbsp;&lt;/td&gt;
                 &lt;td colspan="2"&gt; &lt;strong&gt;Login&lt;/strong&gt;&lt;/td&gt;
                 &lt;td width="22"&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td height="35"&gt;
                    &lt;div align="right"&gt;User Name : &lt;/div&gt;
                 &lt;/td&gt;
                 &lt;td colspan="2"&gt;&lt;label&gt;
                    &lt;input type="text" name="name" id="name" /&gt;&lt;/label&gt;
                 &lt;/td&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td&gt;
                    &lt;div align="right"&gt;Password : &lt;/div&gt;
                 &lt;/td&gt;
                 &lt;td colspan="2"&gt;&lt;input type="password" name="password" id="password" /&gt;&lt;/td&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td&gt;
                    &lt;div align="right"&gt;select your role : &lt;/div&gt;
                 &lt;/td&gt;
                 &lt;td colspan="2"&gt;
                    &lt;!--  &lt;input type="radio" checked="checked" name="title" value="member" id="member" /&gt; member&lt;/label&gt;
                       &lt;label for="admin"&gt; &lt;input type="radio" name="title" value="admin" id="admin" /&gt; admin&lt;/label&gt; --&gt;
                    &lt;label&gt;
                       &lt;select name="member" id="member"&gt;
                          &lt;option title="title" value="member"&gt; member
                          &lt;option title="title" value="admin"&gt; admin
                       &lt;/select&gt;
                    &lt;/label&gt;
                 &lt;/td&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                 &lt;td width="69"&gt;&lt;label&gt;
                    &lt;input type="submit" name="Submit" value="Login" id="add" /&gt;&lt;/label&gt;
                 &lt;/td&gt;
                 &lt;td width="127"&gt;&lt;label&gt;
                    &lt;input type="reset" name="reset" value="reset" /&gt;&lt;/label&gt;
                 &lt;/td&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
                 &lt;td&gt;&lt;a href="register.php"&gt;Register ?&lt;/a&gt; &lt;/td&gt;
                 &lt;td&gt;&lt;a href="forget_password.php"&gt;Forget Password?&lt;/a&gt; &lt;/td&gt;
                 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
              &lt;/tr&gt;
           &lt;/form&gt;
        &lt;/table&gt;
        &lt;script&gt;
           function validate()
           {
              if( document.form1.name.value == "" )
              {
                  alert( "Please provide your name!" );
                  document.form1.name.focus() ;
                  return false;
              }
              if( document.form1.password.value == "" )
              {
                  alert( "Please provide your password!" );
                  document.form1.password.focus() ;
                  return false;
              }
           }
        &lt;/script&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php
      session_start();
      include('connect.php');
      $name = $_POST['name'];
      $password = $_POST['password'];
      $role = $_POST['member'];
      $sql = "select * from login_register where name = '$name' 
      and password = '$password' and role = '$role'";
      $retain = mysql_query($sql, $con);
      // Mysql_num_row is 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  "&lt;a href='index.php'&gt;click here to login   &lt;/a&gt;";
      }
  ?&gt;
  </code></pre>
  
  <p>I just want to indicate user your name is wrong ur password is wrong ur role is wrong .,
  using any validations like ajax/javascript or any other.</p>