Allora, con questi 2 script dovresti avere il risultato che hai chiesto:
regForm.php
Codice PHP:
<?php
$db_server = "server";
$db_user = "username";
$db_password = "password";
$db_name = "database";
$db_conn = mysql_connect($db_server, $db_user, $db_password);
mysql_select_db($db_name, $db_conn);
$query = "SELECT username FROM users WHERE username = '".$_POST['username']."';";
$result = mysql_query($query, $db_conn);
$num_rows = mysql_num_rows($result);
if($num_rows)
header("Location: regForm.php?error=1&username=".$_POST['username']);
else
header("Location: regForm.php?username=".$_POST['username']);
mysql_close($db_conn);
?>
reg.php
Codice PHP:
<html>
<head>
<title>Registrazione</title>
</head>
<body>
<form action="reg.php" method="POST">
Username: <input type=text name="username" value="" />
<?php
if($_GET['username'] != null)
{
if($_GET['error'])
echo "<font color=red>Il nome utente ".$_GET['username']." è già utilizzato!</font>";
else
echo "<font color=green>Il nome utente ".$_GET['username']." è disponibile!</font>";
}
?>
<input type=submit value="Registrati" />
</form>
</body>
</html>
Non è il massimo della sicurezza, ma funziona.