Ciauz...

Dopo aver tribulato un po' , ho finito di scrivere il codice per controllare i campi di un form e restituirne gli errori.
Tutto funziona correttamente, se l'username o la mail sono errati , non compilati ecc..mi riporta al modulo e mi indica gli errori commessi, solo che lo script mi inserisce i dati nel database anche se sono stati riscontrati degli errori, sapete dirmi dove sbaglio?

posto il codice:
Codice PHP:

session_start
();

function 
check_mail($m) {
    
$r "([a-z0-9]+[._-]?){1,3}([a-z0-9])*";
    
$r "^{$r}@{$r}.[a-z]{2,6}$";
    return 
eregi($r$m);
}
$check=$_POST['accept'];
$uuser=$_POST['username'];
$upass=$_POST['password'];
$umail=$_POST['mail'];
$dati=array($uuser,$umail);
$user_long=strlen($uuser);
$pass_long=strlen($upass);
$long_dati=array($user_long,$pass_long);

if (empty(
$uuser) or empty($upass) or empty($umail))
     {
          if (empty(
$uuser))
               {
                    
$user_error="empty";
               }

          else if (!empty(
$uuser) and $user_long<4)
               {
                    
$user_error="length";
               }

          else
               {
                    
$user_error="ok";
               }

          if (empty(
$upass))
               {
                    
$pass_error="empty";
               }

          else if (!empty(
$upass) and $pass_long<4)
               {
                    
$pass_error="length";
               }

          else
               {
                    
$pass_error="ok";
               }

          if (empty(
$umail))
               {
                    
$mail_error="empty";
               }

          else if (!empty(
$umail) and !check_mail($umail))
               {
                    
$mail_error="false";
               }

          else
               {
                    
$mail_error="ok";
               }
          
$error=array($user_error,$pass_error,$mail_error,$check);
          
$_SESSION['error']=$error;
          
$_SESSION['fail']="on";
          
$_SESSION['dati']=$dati;
          
header ("Location:../public/moduli/register.php?".SID);

     }

else if (
$user_long<or $pass_long<4)
     {
           if (
$user_long<4)
               {
                    
$user_error="length";
               }
           else
               {
                    
$user_error="ok";
               }
           if (
$pass_long<4)
               {
                    
$pass_error="length";
               }
           else
               {
                    
$pass_error="ok";
               }

           if (!empty(
$umail) and (!check_mail($umail)))
               {
                    
$mail_error="false";
               }

           else
               {
                    
$mail_error="ok";
               }
            
$error=array($user_error,$pass_error,$mail_error,$check);
            
$_SESSION['error']=$error;
            
$_SESSION['fail']="on";
            
$_SESSION['dati']=$dati;
            
header ("Location:../public/moduli/register.php?".SID);
     }

else if (!empty(
$umail) and (!check_mail($umail)))
     {
           
$user_error="ok";
           
$mail_errorù="ok";
           
$pass_error="ok";
           if (empty(
$umail))
               {
                    
$mail_error="empty";
               }

           else if (!empty(
$umail) and (!check_mail($umail)))
               {
                    
$mail_error="false";
               }

           else
               {
                    
$mail_error="ok";
               }
           
$error=array($user_error,$pass_error,$mail_error,$check);
           
$_SESSION['error']=$error;
           
$_SESSION['fail']="on";
           
$_SESSION['dati']=$dati;
           
header ("Location:../public/moduli/register.php?".SID);
     }
else
  {

    if (
$check!="si")
      {
        
$error=array("ok" "ok" "ok",$check);
        
$_SESSION['dati']=$dati;
        
$_SESSION['fail']="on";
        
$_SESSION['error']=$error;
        
header ("Location:../public/moduli/register.php?".SID);
      }
  }

include (
"../include/dati.php");
include (
"../include/db1.php");

$control="select username , mail  from utenti where username='$uuser' or mail='$umail'";


$q_control=mysql_query($control) or die ("errore nel database");


$num_result=mysql_num_rows($q_control);


$str_result=mysql_fetch_assoc($q_control);


echo 
$num_result;


if (
$num_result>0)
     {
          if (
$uuser==$str_result['username'])
               {
                    
$sql_user="exist";
               }

          else
            {
              
$sql_user="ok";
            }

          if (
$umail==$str_result['mail'])
               {
                    
$sql_mail="exist";
               }

          else
            {
              
$sql_mail="ok";
            }
          
$sql_error=array($sql_user,$sql_mail);
          
$_SESSION['sql_fail']=$sql_error;
          
$_SESSION['dati']=$dati;
          
header ("Location:../public/moduli/register.php?".SID);
     }

else

     {
         
$insert="insert into utenti (username, password, mail,reg) values ('$uuser' , '$upass' , '$umail' , 'no')";
         
$q_insert=mysql_query($insert) or die (mysql_error());

     }