0

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?

4
  • Add redirect after database record update. Commented May 17, 2021 at 18:09
  • yes i tried that. It works, but when i redirect, other page content all refreshed and disappear. I want to keep other content on page, so I can't use redirect solution. Commented May 17, 2021 at 18:15
  • There is no reason why other content should disappear. You are doing st. wrong. Commented May 17, 2021 at 18:16
  • other content just match calculating numbers get total by javascript show on textbox when hit the form submit button, if refresh page, all javascript result are disappear. Commented May 17, 2021 at 19:20

2 Answers 2

1

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");
Sign up to request clarification or add additional context in comments.

Comments

0

Redirect back to the same page for it to get refreshed on submit.

Comments

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.