Pongo el que tengo:
Código PHP:
Ver original
<?php require_once('Connections/conexionzulo.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { } $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": break; case "double": break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } // *** Redirect if email exists $MM_flag="MM_insert"; $MM_dupKeyRedirect="alta_emailrepetido.php"; $loginUsername = $_POST['strEmail']; $LoginRS__query = sprintf("SELECT * FROM tblusuario WHERE strEmail=%s", GetSQLValueString($loginUsername, "text")); //if there is a row in the database, the email was found - can not add the requested username if($loginFoundUser){ $MM_qsChar = "?"; //append the email to the redirect page $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; exit; } } // *** Redirect if username exists $MM_flag="MM_insert"; $MM_dupKeyRedirect="alta_usuariorepetido.php"; $loginUsername = $_POST['strNombre']; $LoginRS__query = sprintf("SELECT * FROM tblusuario WHERE strNombre=%s", GetSQLValueString($loginUsername, "text")); //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 $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername; exit; } } $editFormAction = $_SERVER['PHP_SELF']; } $insertSQL = sprintf("INSERT INTO tblusuario (strNombre, strEmail, intActivo, strPassword, strDireccion) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['strNombre'], "text"), GetSQLValueString($_POST['strEmail'], "text"), GetSQLValueString($_POST['intActivo'], "int"), GetSQLValueString($_POST['strPassword'], "text"), GetSQLValueString($_POST['strDireccion'], "text")); $insertGoTo = "alta_ok.php"; $insertGoTo .= $_SERVER['QUERY_STRING']; } } ?> <!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/Principal.dwt.php" codeOutsideHTMLIsLocked="false" --> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <!-- InstanceBeginEditable name="doctitle" --> <title>El Zulo</title> <!-- InstanceEndEditable --> <!-- InstanceBeginEditable name="head" --> <script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> <link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> <!-- InstanceEndEditable --> <link href="estilo/principal.css" rel="stylesheet" type="text/css" /> </head> <body> <div class="container"> <div class="header"><div class="headerinterior"><img src="images/banner1.jpg" alt="Tienda Zulo" width="980" height="180" /></div> </div> <div class="subcontenedor"> <div class="sidebar1"> <?php include("includes/catalogo.php"); ?> <!-- Incluimos el catalogo que llama a la base de datos --> <!-- end .sidebar1 --></div> <div class="content"> <h1><!-- InstanceBeginEditable name="Titulo" -->Alta Usuario<!-- InstanceEndEditable --></h1> <!-- InstanceBeginEditable name="Contenido" --> <p>Formulario de Alta: </p> <p> </p> <form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1"> <table align="center"> <tr valign="baseline"> <td nowrap="nowrap" align="right">Nombre:</td> <td><span id="sprytextfield1"> <input type="text" name="strNombre" value="" size="32" /> <span class="textfieldRequiredMsg">Este campo es obligatorio.</span></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Email:</td> <td><span id="sprytextfield2"> <input type="text" name="strEmail" value="" size="32" /> <span class="textfieldRequiredMsg">Este campo es obligatorio.</span><span class="textfieldInvalidFormatMsg">El Email no es correcto.</span></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Contraseña:</td> <td><span id="sprytextfield3"> <input type="password" name="strPassword" value="" size="32" /> <span class="textfieldRequiredMsg">Este campo es obligatorio.</span></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right">Direccion:</td> <td><span id="sprytextfield4"> <input type="text" name="strDireccion" value="" size="32" /> <span class="textfieldRequiredMsg">Necesitamos la direccion para enviar el pedido.</span></span></td> </tr> <tr valign="baseline"> <td nowrap="nowrap" align="right"> </td> <td><input type="submit" value="Registrame!" /></td> </tr> </table> <input type="hidden" name="intActivo" value="1" /> <input type="hidden" name="MM_insert" value="form1" /> </form> <p> </p> <script type="text/javascript"> var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1"); var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "email"); var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3"); var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4"); </script> <!-- InstanceEndEditable --><!-- end .content --></div> <!-- end .subcontenedor --></div> <div class="footer"> <p>Pie de Pagina.</p> <!-- end .footer --></div> <!-- end .container --></div> </body> <!-- InstanceEnd --></html>
Me gustaria algo asi... Que se requieran los campos, me gustaria tener 2 campos para contraseña y email para repetirlos y comprobar que coinciden... Y lo mas importante me gustaria que comprobase si el nombre o el mail existe ya en la base de datos.. Y redireccionarlo a alguna pagina de error (como lo tengo puesto yo) o avisarlo en el mismo formulario. La cosa es que no se por donde empezar...
El form action puede ser la misma pagina donde este el formulario, no ?