<?php
	include 'connexion.php';
	include 'escape_valeur.php';
	
	if(isset($_POST['username']) && $_POST['username'] != '')
	{
		if (isset($_POST['id']))
			$requete = 'SELECT * FROM isoactif_t_usager_ecole WHERE u_login = \'' . escape_valeur($_POST['username']) . '\' AND u_id != \'' . escaper_valeur($_POST['id']) . '\'';
		else
			$requete = 'SELECT * FROM isoactif_t_usager_ecole WHERE u_login = \'' . escape_valeur($_POST['username']) . '\'';
		
		if(!$resultat = $connexion->query($requete)){ die('There was an error running the query [' . $connexion->error . ']');}
		
		// Si le nom d'usager choisi est libre
		if ($resultat->num_rows == 0)
			echo 'success';
		else
			echo 'failure';
	}
	
	$connexion->close();
?>