<?php
  session_start();
//Database Configuration File
include('connection.php');
  
     
    	if(isset($_POST['login'])){
    		if($_POST['username'] != "" || $_POST['password'] != ""){
    			$username = $_POST['username'];
    			$password = $_POST['password'];
    			$sql = "SELECT `username`, `password` FROM `admin` WHERE 1";
    			
    			$query = $dbh->prepare($sql);
    	
    			$query->execute(array($username,$password));
    			$row = $query->rowCount();
    // 				print_r($row);
    // 		exit();
    			$fetch = $query->fetch();
    			
    			if($row > 0) {
    
    				$_SESSION['user'] = $fetch['id'];
    				header("location: index.php");
    			} else{
    				echo "
    				<script>alert('Invalid username or password')</script>
    				<script>window.location = 'login.php'</script>
    				";
    			}
    		}else{
    			echo "
    				<script>alert('Please complete the required field!')</script>
    				<script>window.location = 'login.php'</script>
    			";
    		}
    	}
    ?>