
03/06/2015, 15:35
|
| | Fecha de Ingreso: junio-2013
Mensajes: 20
Antigüedad: 11 años, 8 meses Puntos: 0 | |
error al realizar alta en php/mysql Hola tengo la siguiente codificación:
Código:
<html>
<head>
<title>Formulario de registro</title>
</head>
<body>
<h2>Ingrese sus datos</h2>
<form action="registracion.php" method="POST">
<p><label for="nombre">Nombre: </label><br>
<input type="text" name="nombre"></p>
<p><label for="apellido">Apellido: </label><br>
<input type="text" name="apellido"></p>
<p><label for="email">Email: </label><br>
<input type="text" name="email"></p>
<p><label for="dni">DNI: </label><br>
<input type="text" name="dni"></p>
<label for="sexo">Sexo: </label><br>
<select name="sexo" id="ubicacion">
<option value="" selected="selected">-</option>
<option value="F">Femenino</option>
<option value="M">Masculino</option>
</select>
<br /><br />
Fecha
<!-- <input type="text" name="dia" size="2">
<input type="text" name="mes" size="2">
<input type="text" name="anio" size="4">
<br> -->
<p><input type="submit" value="Registrarse" name="submit"></p>
<p><input type="reset" value="Limpiar"></p>
</form>
<?php
if(isset($_POST["submit"]))
{
$nombre = trim($_POST["nombre"]);
$apellido = trim($_POST["apellido"]);
$email = trim($_POST["email"]);
$sexo = trim($_POST["sexo"]);
$dni = trim($_POST["dni"]);
/* $dia= trim($_POST["dia"]);
$mes= trim($_POST["mes"]);
$anio= trim($_POST["anio"]); */
$response = array();
// if($nombre == "" or $apellido == "" or $dni == "" or $email == "" or $sexo == "" or $dia== 0 or $mes== 0 or $anio== 0)
if($nombre == "" or $apellido == "" or $dni == "" or $email == "" or $sexo == "")
$response[] = "Debes completar todos los campos";
if((strlen($nombre) < 5)||(strlen($nombre) > 10))
$response[] ="El nombre debe tener entre 5 y 10 caracteres";
if(!(filter_var($nombre, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z]*$/")))))
$response[]="Se deben ingresar solo letras";
if((strlen($apellido) < 5)||(strlen($apellido) > 10))
$response[] ="El apellido debe tener entre 5 y 10 caracteres";
if(!(filter_var($apellido, FILTER_VALIDATE_REGEXP, array("options" => array("regexp" => "/^[a-zA-Z]*$/")))))
$response[]="Se deben ingresar solo letras";
if(!is_numeric($dni))
$response[]="Debe tener solo numeros";
if(!filter_var($email,FILTER_VALIDATE_EMAIL ))
"El email no es valido";
/* if (!(checkdate($_REQUEST['mes'],$_REQUEST['dia'],$_REQUEST['anio'])))
$response[] = "La fecha no es valida"; */
if(empty($response))
echo "<p> Sus datos se han enviado correctamente</p>";
else
{
foreach($response as $r)
echo "Errores: ".$r."<br>";
}
}
?>
</body>
</html>
Código:
<html>
<head>
<title>Formulario de registro</title>
</head>
<body>
<br /><br />
<h2>Sus datos son:</h2>
<?php
echo'<br/>';
if (isset($_POST['nombre']))
{
$nombre= $_POST['nombre'];
echo "$nombre";
}
echo'<br/>';
if (isset($_POST['apellido']))
{
$apellido = $_POST['apellido'];
echo "$apellido";
}
echo'<br/>';
if (isset($_POST['dni']))
{
$dni = $_POST['dni'];
echo "$dni";
}
echo'<br/>';
if (isset($_POST['email']))
{
$email = $_POST['email'];
echo "email";
}
echo'<br/>';
if (isset($_POST['sexo']))
{
$sexo = $_POST['sexo'];
echo "$sexo";
}
echo'<br/>';
if (isset($_POST['dia']))
{
$dia = $_POST['dia'];
echo "$dia";
}
echo'<br/>';
if (isset($_POST['mes']))
{
$mes = $_POST['mes'];
echo "$mes";
}
echo'<br/>';
if (isset($_POST['anio']))
{
$anio = $_POST['anio'];
echo "$anio";
}
$host = "localhost";
$user = "root";
$pass = "";
$db = "base";
$nombre=$_POST['nombre'];
$apellido=$_POST['apellido'];
$dni=$_POST['dni'];
$email=$_POST['email'];
$sexo=$_POST['sexo'];
/* $dia=$_POST['dia'];
$mes=$_POST['mes'];
$anio=$_POST['anio'];
$fecha=strtotime($dia.$mes.$anio);
*/
$enlace = conectarBaseDeDatos($host,$user,$pass,$db);
if($enlace)
echo "<br> Conectado exitosamente";
echo '<br><br>';
//$cadena = "INSERT INTO cliente2 ('nombre','apellido','dni','email','sexo') VALUES ('$nombre','$apellido',$dni,'$email',$sexo)";
$cadena = "INSERT INTO cliente2 (nombre,apellido,dni,email,sexo) VALUES ($nombre,$apellido,$dni,$email,$sexo)";
$consulta = mysql_query($cadena,$enlace);
$registros=mysql_affected_rows();
//echo mysql_error($enlace);
echo mysql_errno($enlace) . ": " . mysql_error($enlace). "\n";
if($registros == 1)
{
echo "<br> Registros dados de alta";
}
else
{
echo "no se pudo dar de alta";
}
echo '<br><br>';
function conectarBaseDeDatos($host,$user,$pass,$db)
{
$link=mysql_connect($host,$user,$pass) or die("Error al conectarse al servidor");
mysql_select_db($db) or die("Error al conectarse la base de datos");
return $link;
}
?>
me aparece el error 1064: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '@gg,com,F)' at line 1 no se pudo dar de alta pero nosé en que fallé- |