I have some software called phpVMS installed on my webserver and we are running software called SmartCARS which tracks a plane on a flight simulator and sends the data to the phpVMS software. At the end of the flight a PIREP is filed but for some reason I get an error with MySQL syntax. This is the error:
Time: 10.19.17 08:56:52 Backtrace: DB::write_debug > DB::query > PIREPData::fileReport > ACARSData::FilePIREP > smartCARS::filepirep Query: INSERT INTO phpvms_pireps (`pilotid`, `code`, `flightnum`, `depicao`, `arricao`, `route`, `aircraft`, `load`, `flighttime`, `landingrate`, `submitdate`, `fuelused`, `source`, `log`, `distance`, `rawdata`, `flighttime_stamp`, `exported`, `modifieddate`, `accepted`, `expenselist`, `flighttype`) VALUES ('1', 'MCC', '124', 'EGKK', 'EGKK', '', '24', '140', '00.00', '5537', NOW(), '49', 'smartCARS', 'smartCARS version 2.1.31.0, 2017/10/19 UTC*[07:40:58] Preflight started, flying offline*[07:40:58] Flying FSLabs A320X CFM - Easyjet (new colors) (G-EZTA)*[07:56:02] Engine 1 is on*[07:56:02] Engine 2 is on*[07:56:21] Slew mode entered*[07:56:26] Pushing back with 4979 kg of fuel*[07:56:27] Taxiing to runway*[07:56:36] Taking off*[07:56:38] Climbing, pitch: 0, roll: level, 66 kts*[07:56:42] Touched down early at 5537 fpm, gear level: down, flaps: 0*[07:56:47] Landed in 558 ft, fuel: 4959 kg, weight: 61949 kg*[07:56:47] Taxiing to gate*[07:56:47] The flight may now be ended*[07:56:47] Taxi time was less than 15 seconds*[07:56:47] Arrived, flight duration: 00:00', '0', '', '00:00:00', '0', 'NOW()', '0', '0', 'P'); Error: (1292) - Incorrect datetime value: 'NOW()' for column 'modifieddate' at row 1 ===== I have also tried to change NOW() for DateAdd but I get the same error just with DateAdd replacing NOW() in the error log.
Anyone know what I can do to fix this error?
This is all the code I can find relevant to the query:
$pirepdata['exported'] = 0; $pirepdata['submitdate'] = 'NOW()'; $pirepdata['modifieddate'] = 'NOW()'; $pirepdata['accepted'] = PIREP_PENDING; $pirepdata['expenselist'] = '0'; $pirepdata['flighttype'] = $sched->flighttype; # Do the insert based on the columns here $cols = array(); $col_values = array(); foreach ($pirepdata as $key => $value) { if($key == 'submitdate') { $value = 'NOW()'; } elseif ($key == 'comment') { continue; } else { $value = "'".DB::escape($value)."'"; } $cols[] = "`{$key}`"; $col_values[] = $value; } $cols = implode(', ', $cols); $col_values = implode(', ', $col_values); $sql = 'INSERT INTO ' . TABLE_PREFIX . "pireps ({$cols}) VALUES ({$col_values});"; DB::query($sql); $pirepid = DB::$insert_id; I tried removing the single quote from the code but I get this error
[25-Oct-2017 09:02:27 Europe/London] PHP Fatal error: Call to undefined function now() in /var/www/fly/core/common/PIREPData.class.php on line 710 [25-Oct-2017 09:02:27 Europe/London] PHP Stack trace: [25-Oct-2017 09:02:27 Europe/London] PHP 1. {main}() /var/www/fly/core/smartcars/frame.php:0 [25-Oct-2017 09:02:27 Europe/London] PHP 2. smartCARS::filepirep() /var/www/fly/core/smartcars/frame.php:269 [25-Oct-2017 09:02:27 Europe/London] PHP 3. ACARSData::FilePIREP() /var/www/fly/core/smartcars/interface.php:745 [25-Oct-2017 09:02:27 Europe/London] PHP 4. PIREPData::fileReport() /var/www/fly/core/common/ACARSData.class.php:280 If I try to use the php date function I get this error
[25-Oct-2017 09:04:51 Europe/London] PHP Parse error: syntax error, unexpected 'Y' (T_STRING) in /var/www/fly/core/common/PIREPData.class.php on line 710 [25-Oct-2017 09:04:51 Europe/London] PHP Stack trace: [25-Oct-2017 09:04:51 Europe/London] PHP 1. {main}() /var/www/fly/core/smartcars/frame.php:0 [25-Oct-2017 09:04:51 Europe/London] PHP 2. smartCARS::filepirep() /var/www/fly/core/smartcars/frame.php:269 [25-Oct-2017 09:04:51 Europe/London] PHP 3. ACARSData::FilePIREP() /var/www/fly/core/smartcars/interface.php:745 [25-Oct-2017 09:04:51 Europe/London] PHP 4. spl_autoload_call() /var/www/fly/core/smartcars/interface.php:280 [25-Oct-2017 09:04:51 Europe/London] PHP 5. codon_autoload() /var/www/fly/core/smartcars/interface.php:280
NOW()not'NOW()'date('Y-m-d H:i:s')instead ofNOW()now()is not a PHP function.