<?php
include_once '../admin/include/connect.php';
//============================================================================//
// FUNCTION FOR LOGIN //
//============================================================================//
function login($username, $password){
global $objCon;
if($username != '' && $password != ''){
$checkUser = $objCon->query("SELECT username FROM mettes_user WHERE username = '$username' LIMIT 1");
$checkAdmin = $objCon->query("SELECT username, password, admin FROM rest_user WHERE username = '$username' AND password = '$password' AND admin = 1");
$checkPass = $objCon->query("SELECT username, password FROM mettes_user WHERE username = '$username' AND password = '$password' LIMIT 1");
if(mysqli_num_rows($checkUser) != 1){
header('Location: /Planteskole/index.php?page=home&error=2');
}elseif(mysqli_num_rows($checkPass) != 1){
header('Location: /Planteskole/index.php?page=home&error=3');
}elseif(mysqli_num_rows($checkAdmin) >= 1){
session_start();
$_SESSION['username'] = $username; // for Admin
header('Location: /Planteskole/admin/index.php');
}else{
session_start();
$_SESSION['username'] = $username; // For user
header('Location: /Planteskole/index.php');
}
}else{
header('Location: /Planteskole/index.php?page=home&error=1');
}
}
?>