Codice PHP:
<?php
$nome = htmlentities(strip_tags($_POST["nome"]));
$cognome = htmlentities(strip_tags($_POST ["cognome"]));
$username = htmlentities(strip_tags($_POST ["username"]));
$password = htmlentities(strip_tags($_POST["password"]));
$mail = htmlentities(strip_tags($_POST["mail"]));
if($nome == "")
{
print ("Il nome è obbligatorio
<a href=\"formregistraz.php\">indietro</a>
");
}
elseif($cognome == "")
{
print "Il cognome è obbligatorio
<a href=\"formregistraz.php\">indietro</a>
";
}
elseif($username == "")
{
print "L'username è obbligatorio
<a href=\"formregistraz.php\">indietro</a>
";
}
elseif($password == "")
{
print "La password è obbligatoria
<a href=\"formregistraz.php\">indietro</a>
";
}
elseif($mail == "")
{
print "La mail è obbligatoria
<a href=\"formregistraz.php\">indietro</a>
";
}
else
{
include("config.php");
mysql_connect($db_host,$db_user,$db_password,$db_name) or die ("non riesco a connettermi");
mysql_select_db("$db_name") or die ("Non riesco a selezionare il database");
$sql = "SELECT * FROM utenti WHERE username = '$username'";
$result = mysql_query ($sql) or die (errore_server());
$n = mysql_num_rows($result);
if ($n > 0)
{
function reg_register($data)
{
//registro l'utente
global $_CONFIG;
$id = reg_get_unique_id();
mysql_query("
INSERT INTO ".$_CONFIG['table_utenti']."
(nome, cognome, username, password, mail)
VALUES
('".$data['nome']."','".$data['cognome']."','".$data['username']."',',MD5('".$data['password']."'),'".$data['mail']."', '".time()."','".$id."')");
}
}
else
{
echo "nome utente già occupato
";
echo "<a href=\"java-script:history.back()\">ritenta</a> con un altro username";
}
}
echo "$nome";
mysql_close();
?>
Prova cosi e prova ad aggiungere degli ECHO di debug per vedere il valore della variabile $username e soprattutto prova a mettere un bel $n=0; prima dell'if cosi vedi se il problema è quel controllo del mysql_num_rows.