Ver Mensaje Individual
  #1 (permalink)  
Antiguo 20/08/2010, 11:01
kain_raziel
 
Fecha de Ingreso: junio-2009
Mensajes: 45
Antigüedad: 14 años, 10 meses
Puntos: 1
Pregunta Validar User y Email.

Bueno antes que nada saludos a todos los que entren a revisar este post, antes que nada pues los felicito por todo este crecimiento del foro, los he estado siguiendo desde ya hace un buen tiempo, mi problema radica en lo siguiente:

Tengo un formulario en donde quiero validar tanto el username como el email, si ya existen o no en el sistema que estoy desarrollando, ya que solo puedo validar uno de los dos y no los dos al mismo tiempo,como es esto ahí les va, cuando realizo el registro de un nuevo usuario solo valido si el nombre de usuario ya esta registrado en caso de ser así pues me informa que ese username ya existe, pero lo que quiero es que también me valide el email que es ingresado algo parecido a los formularios de los foros.

No se si me explique bien pero la verdad me seria de mucha ayuda aquí les muestro el código que estoy utilizando, lo separa para que se vea bien pero todo esto lo tengo dentro de un mismo archivo registro.php, la conexión a la base de datos lo hago por medio de otro archivo:

Código PHP:
<?php require_once('Connections/server.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset(
$_POST[$MM_flag])) {
  
$MM_dupKeyRedirect="ya_existe.php";
  
$loginUsername $_POST['username'];
  
$LoginRS__query sprintf("SELECT username FROM usuarios WHERE username=%s"GetSQLValueString($loginUsername"text"));
  
mysql_select_db($database_server$server);
  
$LoginRS=mysql_query($LoginRS__query$server) or die(mysql_error());
  
$loginFoundUser mysql_num_rows($LoginRS);

  
//if there is a row in the database, the username was found - can not add the requested username
  
if($loginFoundUser){
    
$MM_qsChar "?";
    
//append the username to the redirect page
    
if (substr_count($MM_dupKeyRedirect,"?") >=1$MM_qsChar "&";
    
$MM_dupKeyRedirect $MM_dupKeyRedirect $MM_qsChar ."requsername=".$loginUsername;
    
header ("Location: $MM_dupKeyRedirect");
    exit;
  }
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO usuarios (username, password, email, calle, no_int, no_ext, cp, col, del_mun, edo) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['username'], "text"),
                       
GetSQLValueString($_POST['password'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['calle'], "text"),
                       
GetSQLValueString($_POST['no_int'], "int"),
                       
GetSQLValueString($_POST['no_ext'], "int"),
                       
GetSQLValueString($_POST['cp'], "int"),
                       
GetSQLValueString($_POST['col'], "text"),
                       
GetSQLValueString($_POST['del_mun'], "text"),
                       
GetSQLValueString($_POST['edo'], "text"));

  
mysql_select_db($database_server$server);
  
$Result1 mysql_query($insertSQL$server) or die(mysql_error());
}
?>
Y esta parte es el formulario:


Código HTML:
<!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"><!-- InstanceBegin template="/Templates/registro_u.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Documento sin título</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<!-- InstanceEndEditable -->
</head>

<body>
<table width="100%" border="0">
  <tr>
    <td colspan="2"><!-- InstanceBeginEditable name="Editar contenido" -->
    <div align="center">REGISTRO DE USUARIO</div>
        <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
          <table align="center">
        <tr valign="baseline">
          <td nowrap="nowrap" align="right">Nombre de usuario:</td>
          <td><input type="text" name="username" value="" size="32" /></td>
          </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Contraseña:</td>
              <td><input type="password" name="password" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Email:</td>
              <td><input type="text" name="email" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Calle:</td>
              <td><input type="text" name="calle" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">No. interior:</td>
              <td><input type="text" name="no_int" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">No. exterior:</td>
              <td><input type="text" name="no_ext" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">CP:</td>
              <td><input type="text" name="cp" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Colonia:</td>
              <td><input type="text" name="col" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Delegación/Municipio:</td>
              <td><input type="text" name="del_mun" value="" size="32" /></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">Estado:</td>
              <td>
                <p>
                  <select name="edo" id="edo" >
                    <option>NUEVO LEON</option>
                    <option>JALISCO</option>
                    <option>MONTERREY</option>
                    <option>COLIMA</option>
                    <option>TLAXCALA</option>
                    <option>MEXICO</option>
                  </select>
              </p></td>
            </tr>
            <tr valign="baseline">
              <td nowrap="nowrap" align="right">&nbsp;</td>
              <td><input type="submit" value="REGISTRAR" /></td>
            </tr>
          </table>
          <input type="hidden" name="MM_insert" value="form1" />
      </form>
    <p>&nbsp;</p>
    <!-- InstanceEndEditable --></td>
  </tr>
</table>
</body>
<!-- InstanceEnd --></html>