0

Based on search a form wiill be displayed with data based on search . I want to update this data with a button on the search result page. the update doesn't work and when I use var dump null values are returned

please help me out
view:

    <h3> Allowances: </h3>
<div class='panel panel-info'>
    <div class='panel panel-heading'></div>
<?php foreach ($allowance as $data): ?>
 <div class="form-group">
        <?php echo form_label( $data->name); ?>
        <?php echo form_input(['class' => 'form-control', 'name' => 'amount','value' => $data->amount]); ?>
  

      <?php echo form_hidden(['class' => 'form-control', 'name' => 'emp','value' => $data->emp_id]); ?>
<?php echo form_hidden(['class' => 'form-control', 'name' => 'comp','value' => $data->comp_id]); ?>

    </div>

<?php endforeach; ?>

</div>

<a href='<?php echo base_url('payroll/update') ?>' class="btn btn-primary" type='submit'> Update</a>

    COntroller
     public function update(){
        $emp_id = $this->input->get('emp');
        $comp_id =$this->input->get('comp');
        
        
        $d = [
            'amount' =>$this->input->post('amount')
        ];
        $this->payroll_model->update($d,$emp_id,$comp_id);
        var_dump($d);
        $this->session->set_flashdata('success','Successfully updated');
    }
model 

    public function update($d,$emp_id,$comp_id){
//    $array = array('emp_id'=>$emp_id,'comp_id' =>$comp_id);
//    $this->db->where($array);
    $this->db->where('emp_id',$emp_id);
    $this->db->where('comp_id',$comp_id);
    $this->db->update('emp_sal',$d);
    return true;
enter code here
enter code here
enter code here

1 Answer 1

0

The reason why you are getting null values returned is that the line below redirects to the link in href instead of posting user's inputs

<a href='<?php echo base_url('payroll/update') ?>' class="btn btn-primary" type='submit'> Update</a>

To overcome this issue, use a form tag with action attribute that has the value of

base_url('payroll/update')

Such as the following

<?php echo form_open(base_url('payroll/update'), array('method'=>'post')) ; ?>

Replace the a tags you are using with the following input that submits user values instead of just redirecting with null values

<input class="btn btn-primary" type='submit'> Update</input>
2
  • It doesnt get updated,Im getting null values from $emp_id and $comp_id (although the values are in the form), also only the data from the last form is captured
    – sarah
    Jun 25, 2020 at 5:09
  • You need to specify the method in your form tag, make it POST. I have edited the answer. Jun 25, 2020 at 14:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.