<?php
session_start();
ob_start();
require_once("db_connect.php");

$log_mail=htmlspecialchars($_POST["log_mail"]);
$log_password=md5(htmlspecialchars($_POST["log_password"]));


$sql="SELECT * FROM users where us_mail ='$log_mail' and us_password = '$log_password'";
$result = $conn->query($sql);

if ($result->num_rows == 1) {
  while ($user= $result->fetch_assoc()){
		$_SESSION['us_id']= $user ["id"]; 
		$_SESSION['us_name']= $user ["us_name"];
		$_SESSION['us_mail']= $user ["us_mail"];
		$_SESSION['us_password']= $user ["us_password"];
		$_SESSION['admin']= $user ["admin"];
		
  }
    header ("Location: user.php"); 
   
	}else{
	 $_SESSION ["chyba"]= 1;
   	header ("Location: index.php"); 
	   
    
}



ob_end_flush();
?>