<?php
	session_start();
	include 'koneksi.php';
	
	$username = $_POST['username'];
	$password = $_POST['password'];
	$_SESSION['username'] = $username;

	$query = mysqli_query($koneksi, "SELECT * FROM t_user where username='$username' AND password='$password'");
	$masuk = mysqli_fetch_array($query);

	if ($masuk == FALSE) {
		$_SESSION['error'] == TRUE;
		echo "<script>alert('Nama pengguna dan kata sandi tidak valid'); window.location = 'login.php'</script>";
	}
	elseif ($query == TRUE) {
		if ($masuk == TRUE) {
			if($masuk['role'] == 1) {
				$_SESSION['administrator'] = TRUE
				;
				echo "<script>alert('Selamat datang $username'); window.location = 'processbook.php'</script>";
			}
			elseif($masuk['role'] == 2){
				$_SESSION['pengunjung'] = TRUE;
				echo "<script>alert('Selamat datang $username'); window.location = 'checkout.php'</script>";
			}
		}
	}
	?>