<?php
include("connectServer.php");
session_start();

if (isset($_GET['name']) && ctype_alnum ($_GET['name'])){
    $req = $bdd->prepare('SELECT * FROM gUsers WHERE NAME = "' . $_GET['name'] . '"');
	$req->execute();
	$data = $req->fetch();
	if ($data) {
        $_SESSION['id'] = $data['id'];
        $_SESSION['name'] = $data['name'];
        
        $_SESSION['indexMessage'] = "<br><br><p class='bigText'> Login successful ! </p><p class='bigText'> Welcome back on GeoQuiz " . $_GET['name'] . "!</p>";
        $_SESSION['newIndexMessage'] = true;
    }
    else {
        $_SESSION['indexMessage'] = "<br><br><br><br><br><p class='error'> Sorry, but this username doesn't exist... </p>";
        $_SESSION['newIndexMessage'] = true;
    }

    header('Location: ../GeoQuiz', true, 302);
	exit;
}
else {
	echo "FAIL";
}
?>