php - HTML textbox is not updated after form submitted update database record
Get the solution ↓↓↓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?
Answer
Solution:
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");
Answer
Solution:
Redirect back to the same page for it to get refreshed on submit.
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: your lock file does not contain a compatible set of packages. please run composer update.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.