Foros del Web » Programando para Internet » PHP »

Error haciendo UPDATE en campo datetime

Estas en el tema de Error haciendo UPDATE en campo datetime en el foro de PHP en Foros del Web. Saludos, tngo un sistema el cual se trata d una lista de invitados que deben confirmar su asistencia por lo cual ellos seleccionan si van ...
  #1 (permalink)  
Antiguo 26/03/2009, 08:22
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 haciendo UPDATE en campo datetime

Saludos, tngo un sistema el cual se trata d una lista de invitados que deben confirmar su asistencia por lo cual ellos seleccionan si van o no van y se hace un UPDATE en la tabla correspondiente pero a su vez hago un update en el campo fecha que es de tipo datetime y cuando hago el update me dice esto

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 '09:08:58, status=1 WHERE id=1' at line 1

mis codigos son
invitaciones.php
Código PHP:
<?php
require_once('includes/sesion.php');
include(
'conect.php');

$reco "-1";
if (isset(
$_SESSION['id'])) {
    
$reco $_SESSION['id'];
}

$sql="select * from invitados where id = '$reco'";
$sql_exec mysql_query($sql);
$rec mysql_fetch_array($sql_exec);

$confirma=$rec['status']; 

$hoy date("Y-m-d, H:m:s");?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>::: Bienvenidos</title>
<script src="Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<link href="css/estilos.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="723" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="417" height="144" align="right" valign="top" background="imgs/home_upleft.jpg"><table width="200" border="0" cellpadding="0" cellspacing="3" class="verdana-gris-peq">
      <tr>
        <td>Bienvenido
          <?php echo $rec['nombre'];?>
          </span>
          <?php echo $rec['apellido'];?><?php print_r($hoy);?></td>
      </tr>
    </table><br /></td>
<td width="306" rowspan="2" valign="top">
<script type="text/javascript">
<!--
AC_FL_RunContent('codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','306','height','600','src','right','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','right' ); //end AC code
-->
</script>
        <noscript>
          <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="306" height="600">
          <param name="movie" value="right.swf" />
          <param name="quality" value="high" />
          <embed src="right.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="306" height="600"></embed>
        </object>
        </noscript>
        </td>
  </tr>
  <tr>
    <td valign="top"><table width="417" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td colspan="3"><img src="imgs/invitaciones_titulo.jpg" width="417" height="78" /></td>
      </tr>
      <tr>
        <td width="30"><img src="imgs/invitaciones1.jpg" width="30" height="290" /></td>
        <td width="364" valign="top" background="imgs/invitaciones_back.jpg">
        <?php if ($confirma == 2) { ?>
        <!-- -->
        <form id="form2" name="form2" method="post" action="confirmar.php" enctype="multipart/form-data">
          <table align="center" class="textoINDEX">
            <tr valign="baseline" class="textoprincipal">
              <td colspan="2" align="right" nowrap="nowrap"><input type="hidden" name="fecha" value="<?php echo $rec['fecha'?>" /></td>
              </tr>
            <tr valign="baseline" class="textoprincipal">
              <td colspan="2" align="right" nowrap="nowrap">
                <select name="status"  class="textoINDEX">
                  <option value="0">Seleccione</option>
                  <option value="1">Si</option>
                  <option value="2">No</option>
                </select> </td>
            </tr>
            <tr valign="baseline">
              <td align="right" nowrap="nowrap" class="textoprincipal">&nbsp;</td>
              <td><div align="left"></div></td>
            </tr>
            <tr valign="baseline">
              <td align="right" nowrap="nowrap" class="textoprincipal">&nbsp;</td>
              <td><input type="submit" class="textoINDEX" value="Actualizar" /></td>
            </tr>
          </table>
          <!--input type="hidden" name="id" value="<?php #echo $row_Recordset1['id']; ?>" /-->
          <input type="hidden" name="MM_update" value="form2" />
          <input type="hidden" name="id" value="<?php echo $rec['id'?>" />
        </form>
        <!-- -->
        <?php ?></td>
        <td width="23"><img src="imgs/invitaciones2.jpg" width="23" height="290" /></td>
      </tr>
      <tr>
        <td colspan="3"><img src="imgs/invitaciones3.jpg" width="417" height="64" /></td>
      </tr>
    </table></td>
  </tr>
</table>
<a href="invitaciones.php">invitaciones link temporal</a>
</body>
</html>
confirmar.php
Código PHP:
<?php
require_once('Connections/cersol.php');

function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue "") {
    
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
}


if ((isset(
$_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) {

    
$updateSQL sprintf("UPDATE invitados SET fecha=%s, status=%s WHERE id=%s",
    
GetSQLValueString($_POST['fecha'], "datetime"),
    
GetSQLValueString($_POST['status'], "int"),
    
GetSQLValueString($_POST['id'], "int"));

    
mysql_select_db($database_cersol$cersol);
    
$Result1 mysql_query($updateSQL$cersol) or die(mysql_error());

    
$updateGoTo "invitacionconf.php";
    if (isset(
$_SERVER['QUERY_STRING'])) {
    
$updateGoTo .= ( strpos($updateGoTo'?') ) ? "&" "?";
    
$updateGoTo .= $_SERVER['QUERY_STRING'];
    }


    if ( 
headers_sent() ) die('sent');
    
header('Location: ' $updateGoTo);
    exit;
}
?>
alguien ve el error???
si pueden ayudarme les agradeceria d verdad...
Saludos
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...
  #2 (permalink)  
Antiguo 26/03/2009, 08:24
Avatar de karlic0s  
Fecha de Ingreso: abril-2007
Ubicación: Cartagena (Murcia)
Mensajes: 241
Antigüedad: 17 años
Puntos: 18
Respuesta: [S.O.S] Error haciendo UPDATE en campo datetime

Creo que es que tus campos en tu update no coinciden con los de la base de datos, comprueba que tengan exactamente el mismo nombre.
  #3 (permalink)  
Antiguo 26/03/2009, 08:28
Avatar de farra  
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 16 años, 1 mes
Puntos: 20
Respuesta: [S.O.S] Error haciendo UPDATE en campo datetime

Código PHP:

//Me parece que esto esta mal:
$hoy date("Y-m-d, H:m:s");

//Deberia ser asi:
$hoy date("Y-m-d H:i:s"); 
en ves de 'm' pones 'i' como minuto...
y en el formato no se pone ',' (coma)
__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)
  #4 (permalink)  
Antiguo 26/03/2009, 08:34
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: [S.O.S] Error haciendo UPDATE en campo datetime

El uso de i es correcto para el minuto.

Lo que sí está mal es que hay que poner la fecha entre comillas SET fecha='%s' en la consulta.
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #5 (permalink)  
Antiguo 26/03/2009, 08:39
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
karlic0s saludos man, fijate q los campos estan bien

CREATE TABLE IF NOT EXISTS `invitados` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`usuario` text NOT NULL,
`pass` text NOT NULL,
`fecha` datetime NOT NULL,
`nombre` text NOT NULL,
`apellido` text NOT NULL,
`id_pais` int(11) NOT NULL,
`invitados` text NOT NULL,
`status` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;

y farra aun asi sigue saliendo el error!!!!!

Cita:
Iniciado por David el Grande Ver Mensaje
Lo que sí está mal es que hay que poner la fecha entre comillas SET fecha='%s' en la consulta.
pq entre comillas????
__________________
Diseño gráfico, Web, imagen corporativa, publicidad ...

Última edición por GatorV; 26/03/2009 a las 10:29
  #6 (permalink)  
Antiguo 26/03/2009, 10:30
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 11 meses
Puntos: 2135
Respuesta: Error haciendo UPDATE en campo datetime

Porque es un dato no-numerico, si fuera un campo TIMESTAMP sí lo puedes subir como número (sin comillas) pero como es un campo del tipo DATETIME tienes que subirlo con comillas forzosamente.

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 02:27.