<?php
	if(isset($_POST['username']) && $_POST['username'] != '')
	{
		include 'connexion.php';

		// Lors du update account info
		if (isset($_POST['id']))
			$requete = 'SELECT * FROM isoactif_t_usager_ecole WHERE u_login = \'' . escapeValue(trim($_POST['username'])) . '\' AND u_id != \'' . escaperValue($_POST['id']) . '\'';
		else // Pour new account
			$requete = 'SELECT * FROM isoactif_t_usager_ecole WHERE u_login = \'' . escapeValue(trim($_POST['username'])) . '\'';

		if (!$resultat = $connexion->query($requete)){ die('There was an error running the query : Check username');}

		// Si le nom d'usager choisi est libre
		if ($resultat->num_rows == 0)
			echo 'available';
		else
			echo 'taken';

		$connexion->close();
	}
?>
