Foros del Web » Programando para Internet » PHP »

Problema para obtener valores de Post

Estas en el tema de Problema para obtener valores de Post en el foro de PHP en Foros del Web. Hola a todos, Sigo con los problemas en mi formulario. Esta vez obtengo el siguiente error: You have an error in your SQL syntax; check ...
  #1 (permalink)  
Antiguo 03/01/2011, 12:29
 
Fecha de Ingreso: agosto-2009
Mensajes: 349
Antigüedad: 14 años, 8 meses
Puntos: 8
Problema para obtener valores de Post

Hola a todos,

Sigo con los problemas en mi formulario. Esta vez obtengo el siguiente error:

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, '-', 2010)), horas='12', minutos='00' WHERE ID_evento='19'' at line 1


Aparentemente tengo campos vacios pero no deberia ser asi. El formulario es el siguiente:


Código PHP:
Ver original
  1. <?php
  2.  
  3. $sql = "SELECT * FROM eventos WHERE ID_evento = '{$_GET['id']}'";
  4. $res = mysql_query($sql,$conectar);
  5. while ($edit = mysql_fetch_array($res)) {
  6.  
  7. $fecha = $edit['fecha'];
  8. $fecha_partes=explode("-",$fecha);
  9. $aniof = $fecha_partes[0];
  10. $mesf = $fecha_partes[1];
  11. $diaf = $fecha_partes[2];
  12.  
  13. if($edit['categoria'] == 'multimedia') {
  14. $fechafin = $edit['fecha_fin'];
  15. $fechafin_partes=explode("-",$fechafin);
  16. $aniofin = $fechafin_partes[0];
  17. $mesfin = $fechafin_partes[1];
  18. $diafin = $fechafin_partes[2];
  19. ?>
  20. <form method="post" action="org_cp.php?evento=editar&id=<?echo $edit['ID_evento'];?>&cat=<?echo $edit['categoria'];?>&enviar=si">
  21.  
  22. Categoría: <select id="categoria" name="categoria" onchange="d1(this)">
  23. <option value="normal">Evento Programado o espontáneo
  24. <option SELECTED value="multimedia">Evento Multimedia
  25. </select>
  26.  
  27. Fecha de inicio: <input maxlength="2" size="2" id="dia" name="dia" value="<?echo $diaf;?>"> - <input maxlength="2" size="2" id="mes" name="mes" value="<?echo $mesf;?>"> - <input maxlength="4" size="4" id="anio" name="anio" value="<?echo $aniof;?>">
  28.  
  29. Fecha de finalización: <input maxlength="2" size="2" id="diafin" name="diafin" value="<?echo $diafin;?>"> - <input maxlength="2" size="2" id="mesfin" name="mesfin" value="<?echo $mesfin;?>"> - <input maxlength="4" size="4" id="aniofin" name="aniofin" value="<?echo $aniofin;?>">
  30.  
  31. <? } else {?>
  32. <form method="post" action="org_cp.php?evento=editar&id=<?echo $edit['ID_evento'];?>&cat=<?echo $edit['categoria'];?>&enviar=si">
  33.  
  34. Categoría: <select id="categoria" name="categoria" onchange="d1(this)">
  35. <option SELECTED value="normal">Evento Programado o espontáneo
  36. <option value="multimedia">Evento Multimedia
  37. </select>
  38.  
  39. Fecha: <input maxlength="2" size="2" id="dia" name="dia" value="<?echo $diaf;?>"> - <input maxlength="2" size="2" id="mes" name="mes" value="<?echo $mesf;?>"> - <input maxlength="4" size="4" id="dia" name="dia" value="<?echo $aniof;?>">
  40.  
  41. Hora: <input maxlength="2" size="2" id="horas" name="horas" value="<?echo $edit['horas'];?>"> : <input maxlength="2" size="2" id="minutos" name="minutos" value="<?echo $edit['minutos'];?>">
  42.  
  43. <? } ?>
  44.  
  45. Nombre del Evento: <input name="nombre" id="nombre" type="text" value="<?echo $edit['nombre'];?>">
  46.  
  47. Link: <input name="link" id="link" type="text" value="<?echo $edit['link'];?>">
  48.  
  49. <input type="submit" name="submiteditar" id="submiteditar" value="Guardar Cambios">
  50. </form>
  51. <? } ?>

Y esta es la consulta:

Código PHP:
Ver original
  1. if(!empty($_POST['submiteditar'])){
  2.  
  3. if($_GET['cat'] == 'normal') {
  4. $nombre=$_POST['nombre'];
  5. $link=$_POST['link'];
  6. $dia=$_POST['dia'];
  7. $mes=$_POST['mes'];
  8. $anio=$_POST['anio'];
  9. $diafin=$_POST['diafin'];
  10. $mesfin=$_POST['mesfin'];
  11. $diafin=$_POST['diafin'];
  12. $categoria=$_POST['categoria'];
  13. $ID_evento=$_GET['id'];
  14.  
  15. $sql = "UPDATE eventos SET nombre='$nombre', link='$link', categoria='$categoria', fecha=DATE(CONCAT($anio,  '-', $mes,  '-', $dia)), fechafin=DATE(CONCAT($aniofin,  '-', $mesfin,  '-', $diafin)) WHERE ID_evento='$ID_evento'";
  16. $resultado = mysql_query($sql,$conn) or die(mysql_error());
  17. }
  18. if($_POST['categoria'] == 'normal') {
  19. $nombre=$_POST['nombre'];
  20. $link=$_POST['link'];
  21. $dia=$_POST['dia'];
  22. $mes=$_POST['mes'];
  23. $anio=$_POST['anio'];
  24. $horas=$_POST['horas'];
  25. $minutos=$_POST['minutos'];
  26. $categoria=$_POST['categoria'];
  27. $ID_evento=$_GET['id'];
  28.  
  29. $sql = "UPDATE eventos SET nombre='$nombre', link='$link', categoria='$categoria', fecha=DATE(CONCAT($anio,  '-', $mes,  '-', $dia)), horas='$horas', minutos='$minutos' WHERE ID_evento='$ID_evento'";
  30. $resultado = mysql_query($sql,$conn) or die(mysql_error());
  31. }
  32. }

Como ven, tanto el formulario como la sintaxis tienen un condicionante según la categoria seleccionada. Intenté poniendo las variables entre corchetes, POST, doble comilla. Sin resultado alguno.

Espero su ayuda :)
  #2 (permalink)  
Antiguo 03/01/2011, 12:34
Avatar de carlos_belisario
Colaborador
 
Fecha de Ingreso: abril-2010
Ubicación: Venezuela Maracay Aragua
Mensajes: 3.156
Antigüedad: 14 años
Puntos: 461
Respuesta: Problema para obtener valores de Post

prueba esto a ver que te esta llegando
Código PHP:
Ver original
  1. print_r($_POST);
y asi ves cual es el problema, saludos
__________________
aprende d tus errores e incrementa tu conocimientos
it's not a bug, it's an undocumented feature By @David
php the right way
  #3 (permalink)  
Antiguo 03/01/2011, 12:35
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Respuesta: Problema para obtener valores de Post

mira, por eso se acostumbra a definir valores por defecto si alguno viene vacío...
Código PHP:
$anio = ! empty($_POST['anio'])? $_POST['anio']: 2010
eso es algo que no haces, y por mucho que compruebes otros aspectos estos siempre se te escaparan... pon atención...
__________________
Y U NO RTFM? щ(ºдºщ)

No atiendo por MP nada que no sea personal.
  #4 (permalink)  
Antiguo 03/01/2011, 13:47
 
Fecha de Ingreso: agosto-2009
Mensajes: 349
Antigüedad: 14 años, 8 meses
Puntos: 8
Respuesta: Problema para obtener valores de Post

Muchas gracias! funciona perfecto :)

Etiquetas: post
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 17:26.