Foros del Web » Programando para Internet » PHP »

ERROR: ingreso a SQL

Estas en el tema de ERROR: ingreso a SQL en el foro de PHP en Foros del Web. saludos... estoy haciendo un mailing list... pero tngo un problema.. ingresa todo correectamente menos la parte de fecha de nacimiento.. me llega al sql 000-00-00 ...
  #1 (permalink)  
Antiguo 14/09/2007, 10:37
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
ERROR: ingreso a SQL

saludos... estoy haciendo un mailing list... pero tngo un problema.. ingresa todo correectamente menos la parte de fecha de nacimiento.. me llega al sql 000-00-00 no me llegan los datos ingresados... me gustaria q alguien checara el codigo y me dijera si ve algun error...
aqui les dejo
asi llega a la base de datos
  #2 (permalink)  
Antiguo 14/09/2007, 10:38
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: ingreso a SQL

Código PHP:
<?php require('Connections/mailinglist.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  
$insertSQL sprintf("INSERT INTO registro (id, nombre, apellido, email, telefono, ciudad, fecha) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['apellido'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['telefono'], "int"),
                       
GetSQLValueString($_POST['ciudad'], "text"),
                       
GetSQLValueString($_POST['fecha'], "date"));

  
mysql_select_db($database_mailinglist$mailinglist);
  
$Result1 mysql_query($insertSQL$mailinglist) or die(mysql_error());

  
$insertGoTo "mailreg.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_mailinglist$mailinglist);
$query_Recordset1 "SELECT * FROM registro ORDER BY nombre ASC";
$Recordset1 mysql_query($query_Recordset1$mailinglist) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>..// B A S I N G E R //..</title>
<style type="text/css">
<!--
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
    background-image: url(imagenes/fondofondo.jpg);
}
.style1 {
    font-family: Verdana, Arial, Helvetica, sans-serif;
    font-size: 10px;
    color: #686E4C;
}
.style2 {color: #A6AC88}
.style4 {color: #444444}
.style9 {color: #424530; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style10 {color: #A6AC88; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; }
.style11 {color: #94906D; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; }
-->
</style>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<link href="estilos.css" rel="stylesheet" type="text/css" />
</head>

<body>
<table width="760" border="0" cellspacing="0" cellpadding="0">
  <tr>
                      <tr>
                    <td width="73%">&nbsp;</td>
                    <td width="27%" rowspan="2" valign="top">&nbsp;</td>
                  </tr>
                  <tr>
                    <td valign="top"><table width="389" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="403" height="85" align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <tr>
                            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
                              <tr>
                                <td>&nbsp;</td>
                              </tr>
                            </table></td>
                          </tr>
                          <tr>
                            <td><form id="form1" name="form1" method="post" action="">
                            </form>
                            
                              <form action="<?php echo $editFormAction?>" method="post" name="form2" id="form2">
                                <table align="center">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Nombre:</td>
                                    <td><input type="text" name="nombre" value="" size="32" /></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Apellido:</td>
                                    <td><input type="text" name="apellido" 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">Telefono:</td>
                                    <td><input type="text" name="telefono" value="" size="32" /></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Ciudad:</td>
                                    <td><input type="text" name="ciudad" value="" size="32" /></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Fecha:</td>
                                    <td><label>
                                      <select name="fecha" id="fecha">
                                        <option>2007</option>
                                        <option>2006</option>
                                        <option>2005</option>
                                        <option>2004</option>
                                                                            </select>
                                      <select name="fecha" id="fecha2">
                                      <option>01</option>
                                      <option>02</option>
                                      <option>03</option>
                                      <option>04</option>
                                      </select>
                                      <select name="fecha" id="fecha3">
                                      <option>01</option>
                                      <option>02</option>
                                      <option>03</option>
                                      <option>04</option>
                                      </select>
                                    </label></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">&nbsp;</td>
                                    <td><input type="submit" value="Insert record" /></td>
                                  </tr>
                                </table>
                                <input type="hidden" name="id" value="" />
                                <input type="hidden" name="MM_insert" value="form2" />
                              </form>
                              <p>&nbsp;</p></td>
                          </tr>
                        </table></td>
                      </tr>
                      <tr>
                        <td width="403"><table width="398" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                              </html>
<?php
mysql_free_result
($Recordset1);
?>
asi va el codigo.. les deje lo basico .. pues el foro no me deja mas de 10000 caracteres
  #3 (permalink)  
Antiguo 14/09/2007, 10:57
 
Fecha de Ingreso: febrero-2003
Ubicación: D.F.
Mensajes: 74
Antigüedad: 21 años, 2 meses
Puntos: 0
Re: ERROR: ingreso a SQL

Cita:
Iniciado por T4ke0veR Ver Mensaje
Código PHP:

                       GetSQLValueString
($_POST['fecha'], "date"));

                                      <
select name="fecha" id="fecha">
                                        <
option>2007</option>
                                        <
option>2006</option>
                                        <
option>2005</option>
                                        <
option>2004</option>
                                                                            </
select>
                                      <
select name="fecha" id="fecha2">
                                      <
option>01</option>
                                      <
option>02</option>
                                      <
option>03</option>
                                      <
option>04</option>
                                      </
select>
                                      <
select name="fecha" id="fecha3">
                                      <
option>01</option>
                                      <
option>02</option>
                                      <
option>03</option>
                                      <
option>04</option>
                                      </
select>
                                    </
label></td
Mira la onda esta ahi, cual de las tres fechas crees que te toma el insert?

La onda es que tienes que armar la fecha antes de meterla, por que ahi solo te toma el campo fecha, no el id, es decir, cuando lees las variables el sistema no lo hace de este modo: ah, quiere que en esta variable fecha meta fecha1 y fecha2 y fecha3

Entonces, tendras que armarlo, e igual y cambiarle el nombre al form fecha, pon, el id como nombre de campo en lugar de id, es decir, name=fecha1, name=fecha2, name=fecha3

Saludos
__________________
Nos leemos...

Richer
Is 40:31 1Co 16:22
  #4 (permalink)  
Antiguo 14/09/2007, 11:15
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: ingreso a SQL

Código PHP:
<?php   GetSQLValueString($_POST['fecha'], 'date');?>
                                      <select name="fecha" id="fecha">
                                        <option>2007</option>
                                        <option>2006</option>
                                        <option>2005</option>
                                        <option>2004</option>
                                                                            </select>
                                      <select name="fecha2" id="fecha2">
                                      <option>01</option>
                                      <option>02</option>
                                      <option>03</option>
                                      <option>04</option>
                                      </select>
                                      <select name="fecha3" id="fecha3">
                                      <option>01</option>
                                      <option>02</option>
                                      <option>03</option>
                                      <option>04</option>
                                      </select>
sigue dando lo mismo... llega vacio
  #5 (permalink)  
Antiguo 14/09/2007, 11:29
 
Fecha de Ingreso: febrero-2003
Ubicación: D.F.
Mensajes: 74
Antigüedad: 21 años, 2 meses
Puntos: 0
Re: ERROR: ingreso a SQL

es que esta linea no te va a funcionar

GetSQLValueString($_POST['fecha'], 'date')

tienes que armar al fecha antes de temerla

fecha1 = $_request[fecha1];
fecha2 = $_request[fecha2];
fecha3 = $_request[fecha3];

La armas

$theDate = $fecha1."-".$fecha2."-".$fecha3;

Y la metes a la bd

Saludos...
__________________
Nos leemos...

Richer
Is 40:31 1Co 16:22
  #6 (permalink)  
Antiguo 14/09/2007, 11:50
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: ingreso a SQL

Cita:
Iniciado por richerweb Ver Mensaje
es que esta linea no te va a funcionar

GetSQLValueString($_POST['fecha'], 'date')

tienes que armar al fecha antes de temerla

fecha1 = $_request[fecha1];
fecha2 = $_request[fecha2];
fecha3 = $_request[fecha3];

La armas

$theDate = $fecha1."-".$fecha2."-".$fecha3;

Y la metes a la bd

Saludos...
de verdad no t entendi... y disculpa pero es q soy nuevo en php!!!!
  #7 (permalink)  
Antiguo 14/09/2007, 12:00
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: ERROR: ingreso a SQL

Te esta diciendo que tu campo no te va a llegar formateado como quieres, por eso te inserta 0000-00-00, necesitas armar el campo antes del insert y luego pasarlo al insert:
Código PHP:
$fecha $_POST['fecha1'] . "-" $_POST['fecha2'] . "-" $_POST['fecha3'];
$insertSQL sprintf("INSERT INTO registro (id, nombre, apellido, email, telefono, ciudad, fecha) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['apellido'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['telefono'], "int"),
                       
GetSQLValueString($_POST['ciudad'], "text"),
                       
$fecha); 
Saludos.
  #8 (permalink)  
Antiguo 14/09/2007, 12:35
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: ERROR: ingreso a SQL

Código PHP:
<?php require('Connections/mailinglist.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$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;
}
}

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

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
    
$fecha $_POST['fecha1'] . "-" $_POST['fecha2'] . "-" $_POST['fecha3'];
  
$insertSQL sprintf("INSERT INTO registro (id, nombre, apellido, email, telefono, ciudad, fecha) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['nombre'], "text"),
                       
GetSQLValueString($_POST['apellido'], "text"),
                       
GetSQLValueString($_POST['email'], "text"),
                       
GetSQLValueString($_POST['telefono'], "int"),
                       
GetSQLValueString($_POST['ciudad'], "text"),
                       
GetSQLValueString($_POST['fecha'], "date"));

  
mysql_select_db($database_mailinglist$mailinglist);
  
$Result1 mysql_query($insertSQL$mailinglist) or die(mysql_error());

  
$insertGoTo "mailreg.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_mailinglist$mailinglist);
$query_Recordset1 "SELECT * FROM registro ORDER BY nombre ASC";
$Recordset1 mysql_query($query_Recordset1$mailinglist) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?>
Código PHP:
<form id="form1" name="form1" method="post" action="">
                            </form>
                            
                              <form action="<?php echo $editFormAction?>" method="post" name="form2" id="form2">
                                <table align="center">
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Nombre:</td>
                                    <td><input type="text" name="nombre" value="" size="32" /></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Apellido:</td>
                                    <td><input type="text" name="apellido" 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">Telefono:</td>
                                    <td><input type="text" name="telefono" value="" size="32" /></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Ciudad:</td>
                                    <td><input type="text" name="ciudad" value="" size="32" /></td>
                                  </tr>
                                  <tr valign="baseline">
                                    <td nowrap="nowrap" align="right">Fecha:</td>
                                    <td><label>

                                     <select name="fecha" id="$_request[fecha];">
                                        <option>2007</option>
                                        <option>2006</option>
                                        <option>2005</option>
                                        <option>2004</option>
                                                                            </select>
                                      <select name="fecha2" id="$_request[fecha2];">
                                      <option>01</option>
                                      <option>02</option>
                                      <option>03</option>
                                      <option>04</option>
                                      </select>
                                      <select name="fecha3" id="$_request[fecha3];">
                                      <option>01</option>
                                      <option>02</option>
                                      <option>03</option>
                                      <option>04</option>
                                      </select>
                                    </label>
y aun no inserta!!!!!
  #9 (permalink)  
Antiguo 14/09/2007, 14:25
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: ERROR: ingreso a SQL

No pusiste el codigo como lo publique, si te fijas quite el ultimo GetSQLValueString y lo reemplaze por $fecha.

Saludos.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 22:00.