I am using CodeIgniter. in application/views/abc.php
<input type="text" name="company_profit" id="company_profit" value="<?php echo $form_data['company_profit']; ?>" >
in application/controller/Cde.php
$data['form_data'] = $form_data = $this->common->getOneRow("tbl_psb_setting","WHERE id=1"); if(isset($_POST) && count($_POST) > 0) { if($this->form_validation->run()) { $up_data['company_profit'] = $this->input->post('company_profit'); $this->common->updateRecord('tbl_psb_setting',$up_data,"id=1"); } }
When i click submit button, html form submitted, database record success updated. But why HTML textbox “company_profit” value is not updated? I need to press F5 refresh page then only I can see textbox value is updated.
I can see page is refresh when i click “submit” button, which mean html form submitted auto refresh page, so I guess mysql retrieve data from database assign to textbox is too fast before new record updated into database? So I try code php sleep(3); wait 3 seconds then only start retrieve data from database assign into textbox value, but fail, textbox still showing old value. Any idea?
Advertisement
Answer
You are fetching the data before updating it. Just move the fetch below like this:
if(isset($_POST) && count($_POST) > 0) { if($this->form_validation->run()) { $up_data['company_profit'] = $this->input->post('company_profit'); $this->common->updateRecord('tbl_psb_setting',$up_data,"id=1"); } } $data['form_data'] = $form_data = $this->common->getOneRow("tbl_psb_setting","WHERE id=1");