<?php
include('config.php'); 
?>
<!DOCTYPE html>
<html >
  <head>
  <script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["username"].value;
var y=document.forms["myForm"]["password"].value;
if (x==null || x=="")
  {
  /*alert("First name must be filled out");*/
  document.getElementById("error_name").innerHTML="enter the name";
  return false;
  }
  else
  {
  document.getElementById("error_name").innerHTML="";
  }
 if (y==null || y=="")
  {
  document.getElementById("error_password").innerHTML="enter the password";
  return false;
  }
  else
  {
  document.getElementById("error_password").innerHTML="";
  }
}
</script>

    <meta charset="UTF-8">
    <title>India Motors</title>
    <link rel='stylesheet prefetch' href='http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css'>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body> 
 
      <div class="wrapper">
 <div align="center" style="padding-bottom:10px; margin-right:100px; margin-top:-34px;"><?PHP if(isset($_REQUEST['er']) && $_REQUEST['er']==1) echo "<span style=color:red;font-weight:bold>Enter Correct Username And Password</span>";?></div>
    <form class="form-signin" method="post" enctype="multipart/form-data">    
      <h2 class="form-signin-heading"> Login</h2>
      <input type="text" class="form-control" name="username" placeholder="User Name" required autofocus /><span class="error" id="error_name" style="color:red;"></span>
      </br>
      <input type="password" class="form-control" name="password" placeholder="Pass Word" required/> <span class="error" id="error_password" style="color:red;"></span>     
      <input class="btn btn-lg btn-primary btn-block" type="submit" name="submit">  
    </form>
	</div>
  </body>
</html>
<?php
if(isset($_REQUEST['submit']))
{
//echo "select * from tbl_admin where emp_uname='".$_POST['username']."' and emp_password='".$_POST['password']."'";die;
 	 $sql=mysqli_query($conn,"select * from tbl_admin where emp_uname='".$_POST['username']."' and emp_password='".$_POST['password']."'");
	 $f=mysqli_fetch_array($sql);
	 if(mysqli_num_rows($sql)==1)
		 {
			 $_SESSION['sno']=$f['sno'];
			 $_SESSION['emp_name']=$f['emp_name'];
			  $_SESSION['emp_uname']=$f['emp_uname'];
			   $_SESSION['emp_password']=$f['emp_password'];
			 $_SESSION['emp_accno']=$f['emp_accno'];
			 if($f['emp_uname']=="admin" && $f['emp_password']=="123")
			 {
				 header("location:home.php");
			 }
			 else{
			 
			 header("location:homepage.php");
			 }
		 }
	 else
		 {
			header("location:index.php?er=1");

		 }
		 
	}

?>
