Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/09/2010, 17:03
Avatar de Weslyghost
Weslyghost
 
Fecha de Ingreso: septiembre-2010
Ubicación: Arequipa - Peru
Mensajes: 14
Antigüedad: 14 años, 5 meses
Puntos: 0
Evitar Registros Duplicados

hola, hice un formulario y me ayudaron con el php, pero ahora necesito que el campo "dni" no se repita en la BD, aqui les dejo el codigo


del formulario
Código:
<!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>
<title>Registro de Lista</title>


</head>
<body bgcolor="#000000">
<div style="background: url('discoteca.jpg') repeat scroll 0% 0% transparent" align="center"><font color="#ffffff"></font>
<h2><font color="#ffffff" face="tahoma">Registrate y entra gratis todos los viernes*</font></h2><br />
<form method="GET" action="insertar.php" name="formContactos" onSubmit="return ValidarEnvio();">
<font color="#ffffff"><strong>Nombre</strong>&nbsp;&nbsp;
<input name="nombre" type="text" /><br />
<strong>Apellido</strong>&nbsp;&nbsp;<input name="apellido" type="text" /><br />
<strong>DNI</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="dni" maxlength="8" type="text"/><br />
<strong>E-mail</strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input name="email" type="text" /><br />
<br /><input value="Registrar" name="submit" type="submit"></font></form><br />
<strong><font color="#ffffff" face="arial black" size="2px">*PREVIA PRESENTACION DE DNI</font></strong></div>
</body>
</html>
del PHP

Código:
<HTML>
<HEAD>
<TITLE>Insertar.php</TITLE>
</HEAD>
<BODY bgcolor="#000000">
<?php
function Conectarse()
{
   if (!($link=mysql_connect("localhost","user","pass")))
   {
      echo "Error conectando a la base de datos.";
      exit();
   }
   if (!mysql_select_db("base_datos",$link))
   {
      echo "Error seleccionando la base de datos.";
      exit();
   }
   return $link;
}

$link=Conectarse();

	$nombre = $_GET['nombre'];
	$apellido = $_GET['apellido'];
	$dni = $_GET['dni'];
	$email = $_GET['email'];

	mysql_query("insert into lista (nombre,apellido,dni,email) values ('$nombre','$apellido','$dni','$email')",$link);

?>
<font color="#ffffff">
<h2><div align="center">Gracias por registrarte</div></h2>
<div align="center"><a href="lectura.php" target="blank_">Haz clic aqui si deseas ver la lista completa</a><br><br><br>
<a href="javascript: self.close ()">Cerrar esta Ventana</a></div>  
</BODY>
</HTML>