0

I have3 table with name frm_data_aset,frm_monitor,frm_lokasi I want if I insert on frm_data_aset column monitor_aset with dropdown from tabel monitor and lokasi from tabel lokasi. on table monitor column lokasi updated with data same at I insert from tabel data_Aset
this my structure :
enter image description here
enter image description here

now I get error : Unknown column 'frm_monitor' in 'where clause' UPDATE frm_monitor SET lokasi_monitor = '123' WHERE frm_monitor IS NULL

this my controller :

{
    $this->_rules();
    if ($this->form_validation->run() == FALSE) {
        $this->create();
    } else {
        $data = array(
    'lokasi_aset' => $this->input->post('lokasi_aset',TRUE),
    'monitor_aset' => $this->input->post('monitor_aset',TRUE),
    );
        $id= $this->input->post('kd_monitor', TRUE);
        $data = array(
        'lokasi_monitor' => $this->input->post('lokasi_aset'),
    );
        $this->M_monitor->update_lokasi($id,$data);
        $this->M_data_aset->insert($data);
        redirect(site_url('data_aset'));
    }
}

this my model M_monitor

function update_lokasi($id,$data){
$this->db->where('frm_monitor', $id);
$this->db->update('frm_monitor', $data);
}

and this my dropdown monitor at form insert data_aset

<option value="0">Pilih Monitor</option>
            <?php
                $monitor = $this->db->get('frm_monitor')->result();
                foreach ($monitor as $row){
                echo "<option value='$row->kd_monitor' ";
                echo $row->kd_monitor==$monitor_aset?'selected':'';
                echo ">".  strtoupper($row->kd_monitor)."</option>";
                }
            ?>
2
  • can you get the table structure Commented Jan 15, 2018 at 3:56
  • I only can show the link above, but must 10 reputation to show image. Commented Jan 15, 2018 at 4:00

2 Answers 2

2

try changing your model query as like this

    function update_lokasi($id,$data){
$this->db->where('id_monitor', $id);
$this->db->update('frm_monitor', $data);
}

Before that make sure that the post for 'kd_monitor' in the controller is not null

Sign up to request clarification or add additional context in comments.

2 Comments

Unknown column 'id_aset' in 'where clause' UPDATE frm_monitor SET lokasi_monitor = '123' WHERE id_aset IS NULL Can't find 'id_aset' bro, because I write this model om M_monitor
i think your id value is null
0

You should rename the $data variable being passed to $this->M_monitor->update_lokasi() because it will overwrite $data that is going to be passed to $this->M_data_aset->insert() with only 'lokasi_monitor' array on it. Or even better try rename both $data to prevent confusion.

Modify your controller :

{
    $this->_rules();
    if ($this->form_validation->run() == FALSE) {
        $this->create();
    } else {
        $data_aset = array(
            'lokasi_aset' => $this->input->post('lokasi_aset',TRUE),
            'monitor_aset' => $this->input->post('monitor_aset',TRUE),
        );
        $id = $this->input->post('kd_monitor', TRUE);
        $data_monitor = array(
            'lokasi_monitor' => $this->input->post('lokasi_aset'),
        );
        $this->M_monitor->update_lokasi($id,$data_monitor);
        $this->M_data_aset->insert($data_aset);
        redirect(site_url('data_aset'));
    }
}

And change 'frm_monitor' to 'kd_monitor' on the conditional query :

function update_lokasi($id,$data){
    $this->db->where('kd_monitor', $id);
    $this->db->update('frm_monitor', $data);
}

1 Comment

Awesome It Works, Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.