<?php
require("include/connection.php");
session_start();
$error=0;
$msg=0;

?>
<html>
<head>

<link type="text/css" rel="stylesheet" href="styleA1.css"/>
<link type="text/css" href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link type="text/css" href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
	<!-- <link type="text/css" href="css/theme.css" rel="stylesheet"> -->
	<link type="text/css" href="images/icons/css/font-awesome.css" rel="stylesheet">
	<link type="text/css" href='http://fonts.googleapis.com/css?family=Open+Sans:400italic,600italic,400,600' rel='stylesheet'>

    <title>CodeAfrica</title>
</head>
<br><br>
<body >
<div class="wrapper">
		<div class="container">
			<div class="row">
				<div class="module module-login span4 offset4">
                <br><br><br>

                        <form class="form-vertical" method="POST" style="border:1px #075fa8 solid; border-radius:5px; padding:20px 20px; box-shadow: 0 4px 20px rgba(0,0,0,0.3)">
                        <div class="module-head" style="background-color: #fff">
                        <center><img src="image/codeafrq.jpg" class="img-circle" alt="User Image" height="150px" width="150px"></center>
							
							<h2 style="color: #111;text-align: center;">CodeAfrica </h2>
							<hr>
						</div>
					<div class="module-body">
							<div class="control-group">
								<div class="controls row-fluID">
									<input class="span12" type="text"  name="username" placeholder="Username" required>
								</div>
							</div>
							
						</div>
            <div class="module-foot">
							<div class="control-group">
								<div class="controls clearfix">
									<button type="submit" class="btn btn-success btn-block" name="submit">Login</button>
									
								</div>
							</div>
              
<?php if($error){?><div class="alert alert-danger"><strong>ERROR</strong>:<?php  echo htmlentities($error); ?> </div><?php } ?>
						</div>

</form>
</div>

</div>
</div>

</div>

<?php
if (isset($_POST['submit'])) {  
    $username=$_POST['username'];

 
    if($username!=""){ 
      $query="SELECT * from users_tbl WHERE  username='$username'";
      $result=mysqli_query($link,$query);
      
      if ($result) {
        mysqli_num_rows($result);
        $rows = mysqli_fetch_assoc($result);
        
        $dbusername=$rows['username'];

     if ($username==$dbusername) {
          $_SESSION['uID']=$rows['uID'];
          $_SESSION['username']=$rows['username'];
          
        header("location:reset_password.php");
     }
      else {
        $error= "invalid username please try again";
      }

      }else {
        $error= "there is a problem with the server";
      }
       }
      else{
      $error="fill all required detail";
      }
 }
 
?>
</form>
</div>

</div>
</div>

</body>
</html>