ho questa pagina di registrazione:
Codice PHP:
<?php
session_start
();
if (isset(
$_SESSION['autorizzato'])) {
    echo 
"

Effettua il logout</p>"
;
    echo 
'[url="index.php"]Home[/url] | ';
    echo 
'[url="logout.php"]Logout[/url]';
    die;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <script src="script.js" type="text/javascript"></script>
        <title>Registrazione</title>
    </head>
    <body>
        [url="index.php"]Home[/url]
        <form method="post" name="inserisci" action="#" onsubmit="return validate(this);">
            <table>
                <tr>
                    <td>User:</td>
                    <td><input type="text" name="user" /></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><input type="text" name="email" /></td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><input type="password" name="pass" /></td>
                </tr>
                <tr>
                    <td><input type="submit" name="registra" value="Registrati"/></td>
                </tr>
            </table>
        </form>
        <?php
        
include("config.php");
        
$link mysql_connect($host$user$password) or die("Non è possibile connettersi al server
"
);
        
$conn mysql_select_db($db$link) or die("Non è possibile connettersi al db
"
);
        
$user mysql_real_escape_string($_POST['user']);
        
$email mysql_real_escape_string($_POST['email']);
        
$pass mysql_real_escape_string($_POST['pass']);
        
$query "insert into utenti values ('" $user "','" $email "','" $pass "')";
        
$controllo "select * from utenti where nome='" $user "'";
        
$result mysql_query($controllo);
        
$riga mysql_fetch_row($result);
        if (isset(
$_POST['registra'])) {
            if (
$user == null || $email == null || $pass == null) {
                echo 
"Dati mancanti";
            }
            if (
$riga[0] != "") {
                echo 
"Utente gia esistente";
            } else {
                
mysql_query($query$link) or die(mysql_error($link));
                
$_SESSION['autorizzato'] = $user;
//                echo '<script language="javascript">document.location.href="index.php"</script>';
            
}
        }
        
?>
    </body>
</html>
ho messo su anche uno script per il controllo del form in js:
Codice PHP:
function validate(form){
    
fail validateUser(form.user.value);
    
fail += validateEmail(form.email.value);
    
fail += validatePassword(form.pass.value);
    if(
fail==""){
        return 
true;
    } else {
        
alert(fail);
        return 
false;
    }
}

function 
validateUser(field){
    if(
field == ""){
        return 
"Nessun Username inserito.\n";
    } else if(
field.length 5){
        return 
"Lo username deve avere almeno 4 lettere.\n"
    
} else if(/[^a-zA-Z0-9_-]/.test(field)){
        return 
"Sono ammessi solo caratteri a-z, A-Z, 0-9, - e _.\n";
    }
    return 
"";
}

function 
validateEmail(field){
    if(
field == ""){
        return 
"Nessuna Email inserita.\n";
    } else if(!((
field.indexOf(".") > 0) && (field.indexOf("@")) ||/[^a-zA-Z0-9.@_-]/.test(field))){
        return 
"L'indirizzo email non è valido.\n";
    }
    return 
"";
}

function 
validatePass(field){
    if(
field == ""){
        return 
"Nessuna Password inserita.\n";
    } else if(
field.length 5){
        return 
"La password deve avere almeno 5 caratteri.\n";
    } else if(!/[
a-z]/.test(field) || !/[A-Z]/.test(field) || !/[0-9]/.test(field)){
        return 
"Sono richiesti i caratteri a-z, A-Z e 0-9.\n";
    }
    return 
"";

ovviamente nn riesco a far funzionare entrambi.
come posso fare per amalgamare i due codici?