Hello friends I have the following form, it generates an error when I try to insert the input time with the form data, what can I be doing wrong
<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';
};
}
This is the 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_...' –
The error that actually says
it is generated because in your query you use the reserved word from which is reserved by the engine to indicate the table to which said operation will be applied.
Solutions
string
and not as a system reserved word.References