<?php
 ob_start(); session_start();
 require_once('includes/functions.php');

// global $last_query;

// echo $last_query;

$DB_HOST = "localhost";
  $DB_USER = "oscotech_onlineo";
  $DB_PASS = "onlineoscotechpayroll";
  $DB_NAME = "oscotech_onlineoscotechpayroll";
  
  $connect = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME);
  
if ($connect){
//echo "Connected to remote DB";   
}else{
    
   // echo "Not Connected".mysqli_error();
}
//echo "Full Time";
//echo "Use: ".$_POST['username'];

//echo "Pass: ".$_POST['password'];
 if (( !isset($_POST['username'])) OR (!isset($_POST['password']) )) {
// 	// Could not get the data that should have been sent.
 	echo 'Please fill both the username and password fields!';
 }else{

//echo "<br>Username: ".$_POST['username'];

//echo "<br>Password: ".$_POST['password'];
  $output=''; $error='';$success='';
    $username=trim($_POST['username']);
    $password=trim($_POST['password']);
   $auths=mysqli_query($connect,"SELECT * FROM stbiodata WHERE username='$username' AND password='$password' LIMIT 1");
 //($username,$password);
while($auth=mysqli_fetch_array($auths))
{
   if(isset($auth['id']))
   {
      $_SESSION['id']=$auth['id'];
      $_SESSION['name']=strtoupper($auth['fullname']);
       $_SESSION['staffid']=$auth['staffid'];
        $_SESSION['status']=$auth['status'];

     echo  $success='success';

      
    redirect_to('home.php');

}else{
  echo 'Invalid username/password';
}
 
}
   
// if ($error!=''){
//   $output=array(
//     'error'=>$error
//   );
// }

// if ($success!=''){
//         $output=array(
//           'success'=>$success
//         );
//       }
// echo json_encode($output);
 }
?>