in questo codice raccolgo i dati di un form e li inserisco in una tabella.
come posso fare per far sì che se il nome utente esiste già nella tabella calendar_users l'inserimento non avviene e mi compaia la scritta in un popup 'nome utente già esistente' ?

Codice PHP:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  
$insertSQL sprintf("INSERT INTO calendar_users (username, password, fname, lname, userlevel, email, hash, telefono, invitoeventi, quotapagata) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['username'], "text"),
                       
GetSQLValueString($_POST['password'], "text"),
                       
GetSQLValueString($_POST['fname'], "text"),
                       
GetSQLValueString($_POST['lname'], "text"),
                       
GetSQLValueString($_POST['userlevel'], "int"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['hash'], "text"),
                       
GetSQLValueString($_POST['telefono'], "text"),
                       
GetSQLValueString($_POST['invitoeventi'], "int"),
                       
GetSQLValueString($_POST['quotapagata'], "int"));
 
  
mysql_select_db($database_server$server);
  
$Result1 mysql_query($insertSQL$server) or die(mysql_error());
  
$insertGoTo "ultimosocioaggiunto.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));