Código PHP:
<?php
session_start();
mysql_connect('localhost','root','')or die ('Ha fallado la conexión con el servidor: '.mysql_error());
mysql_select_db('tesis')or die ('Error al seleccionar la Base de Datos: '.mysql_error());
function formRegistro(){
?>
<form action="registro.php" method="post">
<table width="970" border="1" cellpadding="1" cellspacing="1" bgcolor="#1F9004">
<tr>
<td width="297"><div align="right">Usuario: </div></td>
<td width="335"><input type="text" name="username" size="30" maxlength="20" /></td>
<td width="334"> </td>
</tr>
<tr>
<td><div align="right">Email:</div></td>
<td><div align="left">
<input type="text" name="email" size="40" maxlength="40" />
</div></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Nombre: </div></td>
<td><input name="nombre" type="text" id="nombre" /></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Apellido: </div></td>
<td><input name="apellido" type="text" id="apellido" /></td>
<td></td>
</tr>
<tr>
<td><div align="right">Password: </div></td>
<td><div align="left">
<input type="password" name="password" size="40" maxlength="10" /></div></td>
<td>Confirma:
<input type="password" name="password2" size="40" maxlength="10" /></td>
</tr>
<tr>
<td><div align="right">Dirección: </div></td>
<td><div align="left">
<input name="direccion" type="text" id="direccion" /></div></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Ciudad o Estado:</div></td>
<td><div align="left">
<input name="estado" type="text" id="estado" /></div></td>
<td> </td>
</tr>
<tr>
<td><div align="right">Pais:</div></td>
<td><div align="left">
<select name="pais" class="selects" id="pais">
<option value="CO" >Colombia</option>
<option value="KM" >Comores</option>
<option value="EC" >Ecuador</option>
<option value="EG" >Egipto</option>
<option value="SV" >El Salvador</option>
<option value="GQ" >Guinea Ecuatorial</option>
<option value="ER" >Eritrea</option>
<option value="EE" >Estonia</option>
<option value="ET">Etiopía</option>
<option value="FK" >Islas Malvinas</option>
<option value="FO" >Islas Faroe</option>
<option value="FJ" >Fiji</option>
<option value="FI" >Finlandia</option>
<option value="FR" >Francia</option>
<option value="IL" >Israel</option>
<option value="IT" >Italia</option>
<option value="JM" >Jamaica</option>
<option value="MX">México</option>
<option value="NG" >Nigeria</option>
<option value="NU" >Niue</option>
<option value="NF" >Norfolk</option>
<option value="MP" >Islas Marianas del Norte</option>
<option value="NO" >Noruega</option>
<option value="OM">Omán</option>
<option value="PK">Paquistán</option>
<option value="PW" >Islas Palau</option>
<option value="PA">Panamá</option>
<option value="PG">Papúa Nueva Guinea</option>
<option value="PY" >Paraguay</option>
<option value="PE">Perú</option>
<option value="PH" >Filipinas</option>
<option value="PN" >Pitcairn</option>
<option value="PL" >Polonia</option>
<option value="PT" >Portugal</option>
<option value="PR" >Puerto Rico</option>
<option value="QA" >Qatar</option>
<option value="RE">Reunión</option>
<option value="RO" >Rumania</option>
<option value="RU" >Rusia</option>
<option value="RW" >Ruanda</option>
<option value="SH" >Santa Helena</option>
<option value="KN" >Saint Kitts y Nevis</option>
<option value="LC">Santa Lucía</option>
<option value="PM" >St. Pierre y Miquelon</option>
<option value="VC" >San Vicente y Granadinas</option>
<option value="WS" >Samoa</option>
<option value="SM" >San Marino</option>
<option value="ST">Santo Tomé y Príncipe</option>
<option value="SA">Arabia Saudí</option>
<option value="SN" >Senegal</option>
<option value="SC" >Seychelles</option>
<option value="SL" >Sierra Leona</option>
<option value="SG" >Singapur</option>
<option value="SK">República Eslovaca</option>
<option value="SI" >Eslovenia</option>
<option value="SB">Islas Salomón</option>
<option value="SO" >Somalia</option>
<option value="ZA">República de Sudáfrica</option>
<option value="ES">España</option>
<option value="LK" >Sri Lanka</option>
<option value="SD">Sudán</option>
<option value="SR" >Surinam</option>
<option value="SJ" >Islas Svalbard y Jan Mayen</option>
<option value="SZ" >Suazilandia</option>
<option value="SE" >Suecia</option>
<option value="CH" >Suiza</option>
<option value="SY" >Siria</option>
<option value="TW">Taiwán</option>
<option value="TJ">Tayikistán</option>
<option value="TZ" >Tanzania</option>
<option value="TH" >Tailandia</option>
<option value="TG" >Togo</option>
<option value="TK" >Islas Tokelau</option>
<option value="TO" >Tonga</option>
<option value="TT" >Trinidad y Tobago</option>
<option value="TN">Túnez</option>
<option value="TR">Turquía</option>
<option value="TM">Turkmenistán</option>
<option value="TC" >Islas Turks y Caicos</option>
<option value="TV" >Tuvalu</option>
<option value="UG" >Uganda</option>
<option value="UA" >Ucrania</option>
<option value="AE">Emiratos Árabes Unidos</option>
<option value="UK" >Reino Unido</option>
<option value="US" >Estados Unidos</option>
<option value="UM" >Islas menores de Estados Unidos</option>
<option value="UY" >Uruguay</option>
<option value="UZ">Uzbekistán</option>
<option value="VU" >Vanuatu</option>
<option value="VA" >Ciudad del Vaticano (Santa Sede)</option>
<option value="VE" selected >Venezuela</option>
<option value="VN" >Vietnam</option>
<option value="VG">Islas Vírgenes (Reino Unido)</option>
<option value="VI">Islas Vírgenes (EE.UU.)</option>
<option value="WF" >Islas Wallis y Futuna</option>
<option value="YE" >Yemen</option>
<option value="YU" >Yugoslavia</option>
<option value="ZM" >Zambia</option>
<option value="ZW" >Zimbabue</option>
</select></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><div align="center">
<input type="submit" value="Registrar" />
</div></td>
<td> </td>
</tr>
</table>
</form>
<?php
}
if (isset($_POST["username"])) {
$username = $_POST["username"];
$nombre= $_POST["nombre"];
$apellido= $_POST["apellido"];
$password = $_POST["password"];
$password2 = $_POST["password2"];
$email = $_POST["email"];
$direccion= $_POST["direccion"];
$estado= $_POST["estado"];
$pais= $_POST["pais"];
if($username==NULL|$password==NULL|$password2==NULL|$email==NULL|$direccion==NULL|$estado==NULL|$pais==NULL|$nombre==NULL|$apellido==NULL) {
echo "un campo está vacio.";
formRegistro();
}else{
if($password!=$password2) {
echo "Las contraseñas no coinciden";
formRegistro();
}else{
$checkuser = mysql_query("SELECT usuario FROM usuarios WHERE usuario='$username'");
$username_exist = mysql_num_rows($checkuser);
$checkemail = mysql_query("SELECT email FROM usuarios WHERE email='$email'");
$email_exist = mysql_num_rows($checkemail);
if ($email_exist>0|$username_exist>0) {
echo "El nombre de usuario o la cuenta de correo estan ya en uso";
formRegistro();
}else{
$query = 'INSERT INTO usuarios (usuario, password, email, nombre, apellido, direccion, estado, pais, fecha)
VALUES (\''.$username.'\',\''.$password.'\',\''.$email.'\',\''.$nombre.'\',\''.$apellido.'\',\''.$direccion.'\',\''.$estado.'\',\''.$pais.'\',\''.date("Y-m-d").'\')';
mysql_query($query) or die(mysql_error());
echo 'El usuario '.$username.' ha sido registrado de manera satisfactoria.<br />';
echo 'Ahora puede entrar ingresando su usuario y su password<br />';
?>
<FORM ACTION="comprobar.php" METHOD="post">
<table width="970" border="1" cellpadding="1" cellspacing="1" bgcolor="#1F9004">
<tr>
<td width="374"><div align="right">Usuario :</div></td>
<td width="218"><p align="left">
<INPUT TYPE="text" NAME="usuario" SIZE=20 MAXLENGTH=20></p></td>
<td width="374"> </td>
</tr>
<tr>
<td><div align="right">Password:</div></td>
<td><div align="left">
<INPUT TYPE="password" NAME="password" SIZE=10 MAXLENGTH=10></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td><p align="center"><INPUT TYPE="submit" VALUE="Ingresar"></p></td>
<td> </td>
</tr>
</table>
</FORM>
<?php
}
}
}
}else{
formRegistro();
}
?>