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<?php
$sql = "SELECT * FROM eventos WHERE ID_evento = '{$_GET['id']}'";
$fecha = $edit['fecha'];
$aniof = $fecha_partes[0];
$mesf = $fecha_partes[1];
$diaf = $fecha_partes[2];
if($edit['categoria'] == 'multimedia') {
$fechafin = $edit['fecha_fin'];
$fechafin_partes=explode("-",$fechafin); $aniofin = $fechafin_partes[0];
$mesfin = $fechafin_partes[1];
$diafin = $fechafin_partes[2];
?>
<form method="post" action="org_cp.php?evento=editar&id=<?echo $edit['ID_evento'];?>&cat=<?echo $edit['categoria'];?>&enviar=si">
Categoría: <select id="categoria" name="categoria" onchange="d1(this)">
<option value="normal">Evento Programado o espontáneo
<option SELECTED value="multimedia">Evento Multimedia
</select>
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;?>">
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;?>">
<? } else {?>
<form method="post" action="org_cp.php?evento=editar&id=<?echo $edit['ID_evento'];?>&cat=<?echo $edit['categoria'];?>&enviar=si">
Categoría: <select id="categoria" name="categoria" onchange="d1(this)">
<option SELECTED value="normal">Evento Programado o espontáneo
<option value="multimedia">Evento Multimedia
</select>
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;?>">
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'];?>">
<? } ?>
Nombre del Evento: <input name="nombre" id="nombre" type="text" value="<?echo $edit['nombre'];?>">
Link: <input name="link" id="link" type="text" value="<?echo $edit['link'];?>">
<input type="submit" name="submiteditar" id="submiteditar" value="Guardar Cambios">
</form>
<? } ?>
Y esta es la consulta:
Código PHP:
Ver originalif(!empty($_POST['submiteditar'])){
if($_GET['cat'] == 'normal') {
$nombre=$_POST['nombre'];
$link=$_POST['link'];
$dia=$_POST['dia'];
$mes=$_POST['mes'];
$anio=$_POST['anio'];
$diafin=$_POST['diafin'];
$mesfin=$_POST['mesfin'];
$diafin=$_POST['diafin'];
$categoria=$_POST['categoria'];
$ID_evento=$_GET['id'];
$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'";
}
if($_POST['categoria'] == 'normal') {
$nombre=$_POST['nombre'];
$link=$_POST['link'];
$dia=$_POST['dia'];
$mes=$_POST['mes'];
$anio=$_POST['anio'];
$horas=$_POST['horas'];
$minutos=$_POST['minutos'];
$categoria=$_POST['categoria'];
$ID_evento=$_GET['id'];
$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'";
}
}
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 :)