Código:
  
 <script type="text/javascript">
function verify_passwords(password1, password2)
{
	// do various checks, this will save people noticing mistakes on next page
	if (password1.value == '' || password2.value == '')
	{
		alert('Escriu les contrasenyes correctament.');
		return false;
	}
	else if (password1.value != password2.value)
	{
		alert('Las contrasenyes no concorden.');
		return false;
	}
	else
	{
		
		var junk_output;
		md5hash(password1, document.forms.register.Contrasenya_md5, junk_output, 0);
		md5hash(password2, document.forms.register.Contrasenyaconfirmacio_md5, junk_output, 0);
		
		return true;
	}
	return false;
}
</script>
<?
if($registrar) {
$host = "localhost";
$user = "ampasant_basquet";
$pass = "50202050";
$db = "ampasant_basquet";
$conectar = mysql_connect($host,$user,$pass);
mysql_select_db($db,$conectar);
$Nom = $_POST['Nom'];
$Email = $_POST['Email'];
$resp = mysql_query("select * from usuarios where nom='$Nom'") or die (mysql_error());
$existe = mysql_num_rows($resp);
if($existe == "0") {
mysql_query("insert into usuarios (Nom,Cognoms,Contrasenya,Email) values ('$Nom','$Cognoms','$Contrasenya','$Email')");
echo "Has estat registrat correctament.";
  
      $From = "[email protected]";
      $FromName = "Bàsquet AMPA Sant Josep";
      $destinatario = $Email;
      $asunto = 'Benvingut/a';
      $body = 'Benvingut/a a la web del bàsquet de l´AMPA,';
      $body .= 'Gracies al teu registre, rebràs les últimes notícies i informacions directament al te correu. I si mai et vols donar de baixa d´aquest servei entra aquí: ';
mail($From, $FromName, $destinatario, $asunto, $body);
}
else {
echo "Aquest usuari ja es troba registrat.";
mysql_close($conectar); }
}
?>
<form action="registrar.php" name="Formulari" method="post" onsubmit="return verify_passwords(Contrasenya, Contrasenyaconfirmacio);">
<table class="tborder" cellpadding="6" cellspacing="1" border="0" width="100%" align="center">
<tr>
	<td class="tcat">Registrar-se a la web de l´AMPA</td>
</tr>
<tr>
	<td class="panelsurround" align="center">
	<div class="panel">
		<div style="width:640px" align="left">
			<div class="smallfont" style="margin-bottom:3px">
				Si et registres, rebràs les ultimes noticies i informacions directament al teu correu
			</div>
			<div class="smallfont" style="margin-bottom:3px">
				<strong>Nom</strong>:<br />
				<input type="text" class="bginput" name="Nom" size="25" maxlength="" value="" id="username" style="width: 212px" onblur="CheckUserName();"/><span id="username_status"></span>
			</div> 
                        <div class="smallfont" style="margin-bottom:3px">
				<strong>Cognoms</strong>:<br />
				<input type="text" class="bginput" name="Cognoms" size="25" maxlength="" value="" id="Cognoms" style="width: 212px" onblur="CheckUserName();"/><span id="username_status"></span>
			</div>
			<fieldset class="fieldset">
				<legend>Contraseña</legend>
				<table cellpadding="0" cellspacing="3" border="0" width="400">
				<tr>
					<td colspan="2">Introduix la contrasenya per a la teva conta</td>
				</tr>
				<tr>
					<td>
						Contrasenya:<br />
						<input type="password" class="bginput" name="Contrasenya" size="25" maxlength="50" value="" onblur="varfield(1);" id="password_1"/>
					</td>
					<td>
						Confirmar Contrasenya:<br />
						<input type="password" class="bginput" name="Contrasenyaconfirmacio" size="25" maxlength="50" value="" onblur="varfield(2);" id="password_2"/>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<span id="password_1_status"></span>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<span id="password_2_status"></span>
					</td>
				</tr>
				</table>
			</fieldset>
			<fieldset class="fieldset">
				<legend>Direcció de Correo Electrònic</legend>
				<table cellpadding="0" cellspacing="3" border="0" width="400">
				<tr>
					<td colspan="2">Escriu una direcció de correu vàlida.</td>
				</tr>
				<tr>
					<td>
						Direcció de Correo Electrònic:<br />
						<input type="text" class="bginput" name="Email" size="25" maxlength="50" value="" dir="ltr" onblur="varfield(3);" id="email_1"/>
					</td>
					<td>
						Confirmar Direcció de Correo Electrònic:<br />
						<input type="text" class="bginput" name="Emailconfirm" size="25" maxlength="50" value="" dir="ltr" onblur="varfield(4);" id="email_2"/>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<span id="email_1_status"></span>
						</td>
					</tr>
					<tr>
						<td colspan="2">
							<span id="email_2_status"></span>
					</td>
				</tr>
				
				</table>
			</fieldset>
			
<fieldset class="fieldset">
	<legend>Pregunta aleatòria</legend>
	<table cellpadding="0" cellspacing="3"  border="0" width="100%">
	<tr>
		<td width="100%" valign="top">
			<div><strong><label for="humanverify">¿Quant es 4+4?</label></strong></div>
			<input type="text" class="bginput" name="humanverify[input]" id="humanverify" size="50" />
			<input id="hash" type="hidden" name="humanverify[hash]" value="f9cc14239bc80c849120b6edbd672204" />
		</td>
	</tr>
	</table>
</fieldset>
		</div>
	</div>
	</td>
</tr>
</table>
	<div style="margin-top:6px">
		<input type="submit" class="button" value="Registrar"/>
		<input type="reset" class="button" name="Reset" value="Reestablir camps" />
	</div>
	</td>
</tr>
</table>
</form>
 
