sinesine sinesine - 1 year ago 74
SQL Question

SQL Syntax Error in PHP code - adding together two values

I keep getting this syntax error in my MySQL code within a PHP file. I'm simply trying to increment/add to the value already in the table with this time variable. If anyone could help me out I'd greatly appreciate it.


$sql = "UPDATE Aircraft
SET MaintenanceFlightTime = (MaintenanceFlightTime + $MaintenanceDuration),
WHERE AircraftID = $AircraftID";


UPDATE Aircraft SET MaintenanceFlightTime = (MaintenanceFlightTime + 00:10:00), WHERE AircraftID = 8
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ':10:00), WHERE AircraftID = 8' at line 2

Answer Source

You cannot just add a string like '01:01:01' to a time column but you can use ADDTIME()

$MaintenanceDuration = '00:10:00';

$sql = "UPDATE Aircraft
        SET MaintenanceFlightTime = ADDTIME(MaintenanceFlightTime, '$MaintenanceDuration')
        WHERE AircraftID = $AircraftID";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download