From 5aad2b095048f82f6c489ce9eaf989ac3751096b Mon Sep 17 00:00:00 2001 From: DevSoftTech Server Date: Sat, 6 Jun 2026 05:33:18 +0530 Subject: [PATCH] Fix database error in complaint field update - remove non-existent updated_at column MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BUGFIX: Database error when saving editable complaint fields PROBLEM: After adding X-Requested-With header, the request reached the controller but threw 'Database error' when trying to update the complaint field. ROOT CAUSE: The ipd_discharge_complaint table does not have an 'updated_at' column. The update query was trying to set: - comp_report or comp_remark (correct) - updated_at (does not exist) ← DATABASE ERROR INVESTIGATION: Checked how complaint rows are inserted elsewhere in the codebase (line 4117-4130). The table has 'update_by' column for tracking changes, not 'updated_at'. SOLUTION: 1. Removed hardcoded 'updated_at' => date(...) from update data 2. Only update the target field (comp_report or comp_remark) 3. Conditionally set 'update_by' if column exists (audit trail) 4. Use session full_name for user tracking Now editable complaint fields save successfully without database errors. --- app/Controllers/Ipd_discharge.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/Controllers/Ipd_discharge.php b/app/Controllers/Ipd_discharge.php index 88fe598..d5bf9d6 100644 --- a/app/Controllers/Ipd_discharge.php +++ b/app/Controllers/Ipd_discharge.php @@ -2836,12 +2836,16 @@ class Ipd_discharge extends BaseController $columnName = $fieldType === 'name' ? 'comp_report' : 'comp_remark'; try { + $updateData = [$columnName => $fieldValue]; + + // Only set update_by if column exists + if ($this->db->fieldExists('update_by', $table)) { + $updateData['update_by'] = $this->session->get('full_name') ?? 'System'; + } + $updated = $this->db->table($table) ->where('id', $complaintId) - ->update([ - $columnName => $fieldValue, - 'updated_at' => date('Y-m-d H:i:s') - ]); + ->update($updateData); if ($updated) { return $this->response->setJSON(['success' => true]);