ho risolto solo che ho un problema e non capisco perchè da l'errore

quando fa il controllo se la username già esiste mi da un errore di query

Codice PHP:
<? session_start() ?>

<form method="post" action="checkerror.php?action=submit">

Username: <input type="text" name="username" value="<?php $username ?>" />

Password: <input type="password" name="password" />

Ripeti Password: <input type="password" name="password2" />

email: <input type="text" name="email" value="<?php $email ?>" />

nome: <input type="text" name="nome" value="<?php $nome ?>" />

cognome: <input type="text" name="cognome" value="<?php $cognome ?>" />

<input type="submit" />



<font color="red"> 
<?
     
foreach ($errori AS $v) {
     echo 
$v '
'
;
}
?>
</font>


</form>
Codice PHP:
<?
include("db_vars.inc");

function 
CheckReg1() {
                 
$errori = array();

                 
$username trim($_POST["username"]);
                 if (
$username == ""
                     {
                     
$errori[0] = "La [b]Username[/b] è obbligatoria";
                     } 
                     else if (
strlen($username) < 6// controllo che la username inserita non sia < di 6 caratteri
                     

                     
$errori[0] = "Il [b]Username[/b] non deve essere inferiore a sei caratteri";
                     } 
                     else if (!
eregi("^([a-zA-Z]{3})([a-zA-Z0-9]*)$"$username))//la username inizia per forza con tre lettere 
                     

                     
$errori[0] ="La [b]Username[/b] utilizzata contiene caratteri invalidi";
                     } 
                                          
                     else {
                         
$query "SELECT * FROM users WHERE username = '$username'";
                         
$result mysql_query($query$link) or die("Errore nella query:".mysql_error());
                         
                         if(
mysql_num_rows($result) > 0) { 
                        
                            
$errori[0] ="la Username è in uso";
                         }
                    
        } return 
$errori;         
}

 switch (
$_GET["action"]) { 

                 case 
"submit"
                 
$errori CheckReg1(); 
                 if (
count($errori) == 0) {include ("ty.php");} 
                 else {include (
"form.php");} 
                 break; 

?>
e questa è la tabella

codice:
CREATE TABLE `users` (
  `iduser` int(11) unsigned NOT NULL auto_increment,
  `username` varchar(45) default NULL,
  `password` varchar(100) default NULL,
  `email` varchar(45) default NULL,
  `activation` int(1) NOT NULL default '0',
  `nome` varchar(45) default NULL,
  `cognome` varchar(45) default NULL,
  PRIMARY KEY  (`iduser`)
);