1

Hola amigos tengo el siguiente formulario, me genera error cuando intento insertar el input time con los datos del formulario, que puedo estar haciendo mal

<form action="workingtime.php" method="post">
<input type="hidden" value="L" name="name_l">
<input type="time" name="from_l" value="<?php  echo date("H:i", strtotime('01:00 AM'));?>" class="form-control">
</form>

*** "working_time.php"

if (!empty($_POST['from_l'])) {
    $from_l = $_POST['from_l'];
    $name_l = $_POST['name_l'];

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql_l = "UPDATE working_time SET from='$from_l' WHERE name='$name_l'";
    if($db->exec($sql_l)){
echo 'Ok';
    }else{
echo 'Error';
    };

} 

como esta compuesta la tabla Tabla WOrking Time

Este es el error

PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'from='01:00' WHERE name='L'' at line 1 in /var/www/html/your6/controllers/workingtime.php:23\nStack trace:\n#0 /var/www/html/your6/controllers/workingtime.php(23): PDO->exec('UPDATE working_...' –

3
  • Y cuál es el error que te da?
    – BetaM
    el 30 jun. 2019 a las 23:13
  • Que tipo de dato usas para almacenar dicho valor?
    – BetaM
    el 30 jun. 2019 a las 23:15
  • Este es el error -- > PHP Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 'from='01:00' WHERE name='L'' at line 1 in /var/www/html/your6/controllers/workingtime.php:23\nStack trace:\n#0 /var/www/html/your6/controllers/workingtime.php(23): PDO->exec('UPDATE working_...' el 30 jun. 2019 a las 23:19

1 respuesta 1

1

El error que de hecho dice

access violation......

se genera pues en tu query usas la palabra reservada from la cual está reservada por el motor para indicar la tabla a la cual se le aplicará dicha operación.

Soluciones

  1. Coloca entre backticks `` o comillas simples invertidas dicha palabra, para indicarle que lo lea como string y no como una palabra reservada del sistema.
  2. Modifica el nombre de dicha columna para evitar estos errores y colócale un nombre descriptivo

Referencias

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.