<?php
session_start();
 
$username = $_POST['username'];
$password = $_POST['password'];

//include_once('confdb.php');
include_once('db.functions.php');
 
//$USERNAME = mysqli_real_escape_string($con, $USERNAME);
		
//$result = mysqli_query($con,"SELECT USER_SEQ_ID, USERNAME, PASSWORD, FULL_NAME, LEVEL FROM users WHERE USERNAME = '$USERNAME' AND PASSWORD = '$PASSWORD'");
 
//$row = mysqli_fetch_array($result);

$row=DB::queryFirstRow( "SELECT* FROM main_login WHERE username = %s AND password = %s", $username, $password );

$counter = DB::count();

//if(mysqli_num_rows($result) == 0) 
if($counter == 0) 
{
	$MESSAGE_FAIL = '<blockquote>
                          <h6>
                              <div style="color:#FF0000" align="justify">Please input correct username & password, if you forgot your password please contact the ICT Helpdesk at 03-88876065.</div>
                          </h6>
                          <br>
                </blockquote>';
    $_SESSION['MESSAGE'] = $MESSAGE_FAIL;
    header('Location: index.php');
}

else { 
		session_regenerate_id(); 
		$_SESSION['username'] = $row['username'];
		$_SESSION['password'] = $row['password'];
		
		session_write_close();
		header('Location:../index.php');
}

?>
