updateController.php

 avatar
jthrx
php
23 days ago
2.5 kB
2
Indexable
  public function update_request_details() {
        // Check if the request_id is available (minimum requirement)
        if ($this->input->post('request_id') && $this->input->post('maintenance_id') && $this->input->post('medicine_id')) {
            // Retrieve data from POST request
            $request_id = $this->input->post('request_id');
            $medicine_id = $this->input->post('medicine_id');
            $medicine_name = $this->input->post('medicine_name');
            $medicine_per_piece = $this->input->post('medicine_per_piece');
            $medicine_quantity = $this->input->post('medicine_quantity');
            $medicine_amount = $this->input->post('medicine_amount');
            $maintenance_id = $this->input->post('maintenance_id');
            $maintenance_name = $this->input->post('maintenance_name');
            $maintenance_per_piece = $this->input->post('maintenance_per_piece');
            $maintenance_quantity = $this->input->post('maintenance_quantity');
            $maintenance_amount = $this->input->post('maintenance_amount');

    
            // Update the medicine details
            $medicine_data = array(
                'medicine_prescribed' => $medicine_name,
                'amount_per_piece' => $medicine_per_piece,
                'medicine_quantity' => $medicine_quantity,
                'amount' => $medicine_amount
            );
            $this->db->where('request_id', $request_id);
            $this->db->where('id', $medicine_id);
            $this->db->update('medicine_details', $medicine_data);
    
            // Update the maintenance details
            $maintenance_data = array(
                'maintenance' => $maintenance_name,
                'amount_per_piece' => $maintenance_per_piece,
                'maintenance_quantity' => $maintenance_quantity,
                'amount' => $maintenance_amount
            );
            $this->db->where('request_id', $request_id);
            $this->db->where('id', $maintenance_id);
            $this->db->update('maintenance_details', $maintenance_data);
    
            // Return a response (success even if no rows changed, as this might be expected)
            echo json_encode(array('status' => 'success', 'message' => 'Request processed'));
        } else {
            echo json_encode(array('status' => 'error', 'message' => 'Missing request ID'));
        }
    }
    
Editor is loading...
Leave a Comment