Código PHP :
<?php $servername = "censurado"; $username = "censurado"; $password = "censurado"; $dbname = "censurado"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Error: " . $conn->connect_error); } $fecha = $_POST['databox']; $tipodeevento = $_POST['tipoEventos']; $otro = $_POST['otroTipoEventos']; $materia = $_POST['materiabox']; $tarea = $_POST['tareabox']; $sql = "INSERT INTO 1esoacalendar (fecha, tipo de evento, otro, materia, asunto, tarea, evento) VALUES ('$fecha', '$tipodeevento', '$otro', '$materia', '$tarea')"; if ($conn->query($sql) === TRUE) { echo "<font face='segoe script' color='#333333' size='+1'>Se guardó correctamente</font>"; echo " "; echo "<a href='calendar.php'><font face='segoe script' color='blue' size='+1'>Volver</font></a>"; } else { echo "<a href='calendar.php'><font face='segoe script' color='#333333' size='+1'>Volver</font></a>", $conn->error; echo " "; echo "<font face='segoe script' color='#333333' size='+1'>Error al guardar los datos</font>"; } $conn->close(); ?>
No me va bien, me da 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 'de evento, otro, materia, asunto, tarea, evento) VALUES ('', '', '', '', '')' at line 1 no se qque significa, creo que esta bien pero no se donde esta el error.
Código PHP :
<!-- Codigo javascript --> <script type='text/javascript'> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; // Si el valor elegido del select == otro, habilitar la caja de texto. if(valor === 'otro'){ var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } }); </script> <style> .btnmás { background-color:transparent; border: transparent; font-size: 30px; cursor: pointer; border-radius: 1000px; font-family: segoe script; } </style> <style> .textbox { background: transparent; font-family: segoe script; border: none; } </style> <style> .btn1 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 20px 20px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn1:hover { background: #ffcc00; text-decoration: none; } </style> <style> .btn2 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 120px 2px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn2:hover { background: #ffcc00; text-decoration: none; } </style> <style> .btn3 { background: #e09410; background-image: -webkit-linear-gradient(top, #e09410, #ffb700); background-image: -moz-linear-gradient(top, #e09410, #ffb700); background-image: -ms-linear-gradient(top, #e09410, #ffb700); background-image: -o-linear-gradient(top, #e09410, #ffb700); background-image: linear-gradient(to bottom, #e09410, #ffb700); -webkit-border-radius: 60; -moz-border-radius: 60; border-radius: 10px; border: none; font-size:15px; font-family: segoe script; padding: 1px 170px 2px 5px; text-decoration: none; width: 1px; height: 30px; cursor: pointer; } .btn3:hover { background: #ffcc00; text-decoration: none; } </style> <style type='text/css'> #tipoEventos { border: inset; border-color: orange; opacity: 0.8; font-family: sgoe script; font-size: 14px; } #tipoEventos option { font-family: sgoe script; color: #333; font-size: 1.5em; } #otroTipoEventos { display: none; border: inset; border-color: orange; opacity: 0.8; font-family:segoe script; font-size: 14px; position: center; } </style> <?php // Establecer el idioma al Español para strftime(). setlocale( LC_TIME, 'spanish' ); // Si no se ha seleccionado mes, ponemos el actual y el año $month = isset( $_GET[ 'month' ] ) ? $_GET[ 'month' ] : date( "Y-n" ); $week = 1; for ( $i=1;$i<=date( 't', strtotime( $month ) );$i++ ) { $day_week = date( 'N', strtotime( $month.'-'.$i ) ); $calendar[ $week ][ $day_week ] = $i; if ( $day_week == 7 ) $week++; } ?> <!DOCTYPE html> <html> <head> <title>Calendario PHP/HTML5</title> <style type="text/css"> table { margin: auto; } </style> </head> <body style="background-image: url('imagenes/fondo ies calvia proyecto.jpg'); background-repeat: no-repeat; background-position: all; background-attachment: fixed; background-size: cover;"> <table border="4" id="calendar" style="border: solid; border-color: #B45F04; background-color: #F7D358; font-family: segoe script; height:650px; width:1300px; font-size:20px;"> <thead> <tr> <td colspan="7"><center><b><?php echo strftime( '%B de %Y', strtotime( $month ) ); ?><b></center></td> </tr> <tr> <td><center><b>Lunes</b></center></td> <td><center><b>Martes</b></center></td> <td><center><b>Miércoles</b></center></td> <td><center><b>Jueves</b></center></td> <td><center><b>Viernes</b></center></td> <td><center><b>Sábado</b></center></td> <td><center><b>Domingo</b></center></td> </tr> </thead> <tbody> <?php foreach ( $calendar as $days ) : ?> <tr> <?php for ( $i=1;$i<=7;$i++ ) : ?> <td> <?php echo isset( $days[ $i ]) ? $days[ $i ] : ''; ?> </td> <?php endfor; ?> </tr> <?php endforeach; ?> </tbody> <tfoot> <tr> <td colspan="7"> <form method="get"> <input type="month" name="month" class="textbox"> <input type="submit" value="ir" class="btn1"> </form> </td> </tr> </tfoot> </table> <?php mysqli_real_escape_string($conn, $_POST['databox']); mysqli_real_escape_string($conn, $_POST['tipoEventos']); mysqli_real_escape_string($conn, $_POST['otroTipoEventos']); mysqli_real_escape_string($conn, $_POST['materiabox']); mysqli_real_escape_string($conn, $_POST['tareabox']); ?> <form id="demo" align="center" action="añadirevento.php"> <font face="segoe script" size="+6" color="#333333">Insertar eventos</font> <br> <font face="segoe script" size="+1" color="#333333">Data:</font> <input type="date" name="databox" style="border: inset;border-color: orange; opacity: 0.8; font-family: segoe script; font-size:14px;" required> <br> <font face="segoe script" size="+1" color="#333333">Tipo de evento:</font> <select name="tipoEventos" id="tipoEventos" style="border: inset;border-color: orange; opacity: 0.8; font-family: segoe script; font-size: 14px;" required> <option value="null" selected disabled><font face="segoe script" size="+1">---Eligir tipo de evento---</font></option> <option value="deberes"><font face="segoe script" size="+1">Deberes</font></option> <option value="trabajos"><font face="segoe script" size="+1">Trabajos</font></option> <option value="controles"><font face="segoe script" size="+1">Controles</font></option> <option value="salidas"><font face="segoe script" size="+1">Salidas</font></option> <option value="vacaciones"><font face="segoe script" size="+1">Vacaciones</font></option> <option value="otro"><font face="segoe script" size="+1">Otro...</font></option> </select> <script type='text/javascript'> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; // Si el valor elegido del select == otro, habilitar la caja de texto. if(valor === 'otro'){ var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'inherit'; var display = document.getElementById('cambiartexto'); display.innerHTML='Asunto:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Evento:'; } }); </script> <script type='text/javascript'> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor = this.value; if(valor === 'vacaciones'){ var display = document.getElementById('cambiartexto'); display.innerHTML='Asunto:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Evento:'; } if (valor == 'salidas') { var display = document.getElementById('cambiartexto'); display.innerHTML='Asunto:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Evento:'; } if (valor == 'deberes') { var display = document.getElementById('cambiartexto'); display.innerHTML='Materia:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Tarea:'; } if (valor == 'trabajos') { var display = document.getElementById('cambiartexto'); display.innerHTML='Materia:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Tarea:'; } if (valor == 'controles') { var display = document.getElementById('cambiartexto'); display.innerHTML='Materia:'; var none = document.getElementById('cambiartextarea'); none.innerHTML='Tarea:'; } }); </script> <script> document.getElementById('tipoEventos').addEventListener('change', function(){ var valor= this.value; if (valor=='deberes') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='trabajos') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='controles') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='salidas') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } if (valor=='vacaciones') { var cajaTexto = document.getElementById('otroTipoEventos'); cajaTexto.disabled = false; cajaTexto.style.display = 'none'; } }); </script> <input type="text" name="TipoEventos" id="otroTipoEventos" style="position:relative; left:880px; top: -30px; display: none;" disabled> <br> <font face="segoe script" size="+1" color="#333333" id="cambiartexto">Materia:</font> <br> <input type="text" name="materiabox" style="border:inset; border-color: orange; opacity: 0.8; font-family: segoe script; font-size: 14px;" oncut="return false" onpaste="return false" oncut="return false" placeholder=" Escribe aquí..." required> <br> <font face="segoe script" size="+1" color="#333333" id="cambiartextarea">Tarea:</font> <br> <textarea name="tareabox" style="border:inset; border-color: orange; opacity: 0.8; font-family: segoe script; font-size:14px;" cols="50" rows="10" placeholder="Escribe aquí..." required></textarea> <br> <input type="submit" name="Enviar" value="Guardar datos" class="btn2"> <input type="reset" name="eliminar" class="btn3" value="Limpiar formulario"> </form> </body> </html>
Gracias.
Atentamente IVAN HEREDIA PLANAS.