Ver Mensaje Individual
  #1 (permalink)  
Antiguo 29/05/2007, 21:17
Avatar de rol2007
rol2007
 
Fecha de Ingreso: mayo-2007
Ubicación: Santiasco CHILE
Mensajes: 300
Antigüedad: 17 años
Puntos: 4
no repetir llaves primarias

ola necesito saber como puedo validar de que no coloquen 2 veces una llave primaria....en el registro de usuarios.....me podrian ayudar?

:D


les mando el codigo

Código PHP:
<?
include ("lib/conexion.php");
$conect=conect();

function 
valida_rut($r)
{
    
$r=strtoupper(ereg_replace('\.|,|-','',$r));
    
$sub_rut=substr($r,0,strlen($r)-1);
    
$sub_dv=substr($r,-1);
    
$x=2;
    
$s=0;
    for ( 
$i=strlen($sub_rut)-1;$i>=0;$i-- )
    {
        if ( 
$x >)
        {
            
$x=2;
        }
        
$s += $sub_rut[$i]*$x;
        
$x++;
    }
    
$dv=11-($s%11);
    if ( 
$dv==10 )
    {
        
$dv='K';
    }
    if ( 
$dv==11 )
    {
        
$dv='0';
    }
    if ( 
$dv==$sub_dv )
    {
        return 
true;
    }
    else
    {
        return 
false;
    }
}

//llamada de la funcion

$ssql=mysql_query("select rut from clientes");

while(
$data=mysql_fetch_array(ssql)){

   
$_POST['rut']==$data;
header("Location:registro.htm");
}

if ( 
valida_rut($_POST['rut']) )
{
        
mysql_query("insert into clientes (rut,pass,nombre,apellidos,direccion,comuna,ciudad,telefono,mail) values ('$rut','$pass','$nombre','$apellidos','$direccion','$comuna','$ciudad','$telefono','$mail')");
        
header("Location:index.html");
}
else
{
     echo 
'el rut es incorrecto ';
     echo 
'<p><a href=registro.htm>Volver</p>';
}


?>