Ver Mensaje Individual
  #4 (permalink)  
Antiguo 05/11/2012, 13:09
Avatar de polarubi
polarubi
 
Fecha de Ingreso: noviembre-2008
Mensajes: 243
Antigüedad: 17 años, 10 meses
Puntos: 2
Respuesta: problema al comprobar campos

Cita:
Iniciado por rolygc Ver Mensaje
Creo ke mas bien es problema de logica, aqui he tratado de organizarlo algo, chequealo a ver si te sirve

Código PHP:
include("../h.home.php"); 

$nick  = trim(mysql_real_escape_string( $_POST['username'] )); 
$email = trim(mysql_real_escape_string( $_POST['email'] )); 

function 
chequearDatos($field, $valor)
{
    
$query = mysql_query( "SELECT " . $field . " FROM usuarios WHERE " . $field . " = '$valor'" ) or die( mysql_error() ); 
    return 
mysql_num_rows( $query ); 
}    

if ( !empty(
$nick) )
{
    if ( 
chequearDatos('nick', $nick) )
    { 
        throw new 
Exception('Username ya exsite');
    }
    
    echo
'{"status":1,"valid":"username"}'; 
    
} 

if( ( !empty(
$email) )
{ 
    if( !
filter_input(INPUT_POST, $email, FILTER_VALIDATE_EMAIL) );
    {    
        throw new 
Exception('Email no valido');
    }
    
    if ( 
chequearDatos('mail', $email) )
    {
        throw new 
Exception('Email en uso');
    }
    
    echo
'{"status":1,"valid":"email"}'; 
    
} 
espero te ayude
buena suerte
muchas gracias pero no me sirvio, al momento de poner cualquier nick, este en uso o no, me sale error :S