<?
session_start();
require 'connect.php';
$connection = new ConnectDatabase();

if (isset($_POST["txtUsr"]) && !empty($_POST["txtUsr"]) && isset($_POST["txtPippo"]) && !empty($_POST["txtPippo"])) {

	$usern = $_POST["txtUsr"];
	$pass = $_POST["txtPippo"];

	$usern = $connection->real_escape_string(strtolower($usern));
	$pass = $connection->real_escape_string($pass);

	$sql = "SELECT nome FROM account_leads WHERE email = '$usern' && motto = md5('$pass')";

	if ($tryLogin = mysqli_query($connection, $sql)) {
		$user = $tryLogin->fetch_row();
		if ($user[0] != "") {

			session_regenerate_id();
			$usrName = $user[0];
			unset($_SESSION['ospite']);
			$_SESSION['ospite'] = $usrName;
			$_SESSION['ospiteM'] = $usern;
			echo "Yis";
		} else {
			echo "Incorrectdata";
		}
	} else {
		echo "Queryfallita";
	}
} else {
	header('Location: https://labakeca.eu/'.$_POST["l"].'/index');
}
mysqli_close($connection);
?>