<?php
ob_start();
session_start();
ini_set('display_errors', 1);
require('../includes/cmain.inc.php');
if(isset($_POST['submit'])){
//echo $_POST['username'];
$sqlquery="SELECT admin_name,admin_password FROM tbl_admin_blog WHERE admin_name='".$_POST['username']."' AND admin_password='".$_POST['password']."'";
$sqlexecute=db_query($sqlquery);
//print_r($sqlquery);exit;
$sqlarray=mysqli_fetch_array($sqlexecute);
$username=$sqlarray['admin_name'] ?? '';
$count=mysqli_num_rows($sqlexecute);
   //    print_r($count);exit;

 if($count=='1'){
   $_SESSION['username'] = $username;
   $_SESSION['logged_in'] = 'true';
 // print_r($_SESSION['logged_in']);exit;

   if(isset($_SESSION['logged_in']) && $_SESSION['logged_in'] == 'true') {
   header("Location: welcome.php");
    exit();	
	  }
	else{
	header("Location: index.php");
	exit();
	  }
 }
 }
 ob_end_flush();
?>

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>Login</title>
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
		<link href="css/admin_style.css" rel="stylesheet" type="text/css">
	</head>
	<body>
		<div class="login">
			<h1>Main Administrator Login</h1>
			<form action="" method="POST">
				<label for="username">
					<i class="fas fa-user"></i>
				</label>
				<input type="text" name="username" placeholder="Username" id="username" required />
				<label for="password">
					<i class="fas fa-lock"></i>
				</label>
				<input type="password" name="password" placeholder="Password" id="password" required />
				<input type="submit" name="submit" value="submit" />
			</form>
		</div>
	</body>
</html>