<?php
session_start();
require_once('fungsi.php');

$username =$_POST ['username'];
$password =$_POST['password'];


$query = "select * from user where username='".$username."' and password='".$password."'";
$sql = mysqli_query($conn, $query);

$check = mysqli_num_rows($sql);
$r = mysqli_fetch_array($sql);

if($check>=0){
	$_SESSION['username'] = $username;
	$_SESSION['password'] = $password;
	$_SESSION['role'] = $r['role'];
	$_SESSION['nama'] = $r['namalengkap'];
	$_SESSION['alamat'] = $r['alamat'];
	$_SESSION['email'] = $r['email'];
	
	
	if($r['role']=='admin'){
		header('LOCATION: home.php');
		$_SESSION['admin'] = TRUE;
	}elseif($r['role']=='user'){
		header('LOCATION: index.php');
		$_SESSION['user'] = TRUE;
		$_SESSION['is_logged_in']=TRUE;
		$_SESSION['username']=$username;
	}
	elseif($r['username'] != $username && $r['password'] != $password){
		echo "<script language='javascript'>alert('cek username dan Password anda')</script>";
		echo "<script>window.location = 'login.php'</script>";
	}
}
?>