0

I am calling the controller function via ahref tag and i want to pass the current record no to the controller to update the record current value is stored in$currentID and i pass this value in input type..but i didn't get the value from the view page..i tried var_dump($id)..it shows null Controller Code to update:

 public function update($id='') { $session_data = $this->session->userdata('logged_in'); $data['username'] = $session_data['username']; $id=$this->input->post('update'); echo "<pre>";var_dump($id); $dc=$this->input->post('dc'); if($dc=='c'){ $amount=$this->input->post('credit1'); } else if ($dc=='d') { $amount=$this->input->post('debit'); } $data=array( 'date' =>$this->input->post('TDate'), 'code' =>$this->input->post('TName'), 'project' =>$this->input->post('TName1'), 'part' =>$this->input->post('part1'), 'part1' =>$this->input->post('part2'), 'dc'=>$this->input->post('dc'), 'amount'=>$amount, ); $this->db->where('recno', $id); $this->db->update('daybook', $data); $this->session->set_flashdata('Add1', 'Updated Successfully'); redirect('BookKeeping/daybook','refresh'); } 

calling update

<a href="<?=site_url('BookKeeping/update/'.$currentID)?>" class="btn btn-info btn-"><i class="icon-new position-left"> <input type="hidden" name="update" id="id" value="<?php echo $currentID?>"> </i>Update</a> 

Help me to pass the currentvalue to the controller..Thanks in advance

4
  • you are passing $id in GET method, so use direclty instead of POST Remove this $id=$this->input->post('update'); echo "<pre>";var_dump($id); directly echo $id; Commented Dec 10, 2018 at 11:43
  • You can't get any input filed record while you using a href if you need the input field record then you have to use form Commented Dec 10, 2018 at 11:44
  • Okey...i have used form also Commented Dec 10, 2018 at 11:47
  • I have comment my anser Commented Dec 10, 2018 at 11:48

3 Answers 3

2

you are sending value in url change this

$id=$this->input->post('update'); 

To

$id=$this->uri->segment('3'); 
Sign up to request clarification or add additional context in comments.

Comments

1

remove the input field. You can't pass any input data with

<a href="<?=site_url('BookKeeping/update/'.$currentID)?>" class="btn btn-info btn-"><i class="icon-new position-left"></i>Update</a> 

Try this

public function update($id=''){ $session_data = $this->session->userdata('logged_in'); $data['username'] = $session_data['username']; $id=$id; echo "<pre>";var_dump($id); $dc=$this->input->post('dc'); if($dc=='c'){ $amount=$this->input->post('credit1'); } else if ($dc=='d') { $amount=$this->input->post('debit'); } $data=array( 'date' =>$this->input->post('TDate'), 'code' =>$this->input->post('TName'), 'project' =>$this->input->post('TName1'), 'part' =>$this->input->post('part1'), 'part1' =>$this->input->post('part2'), 'dc'=>$this->input->post('dc'), 'amount'=>$amount, ); $this->db->where('recno', $id); $this->db->update('daybook', $data); $this->session->set_flashdata('Add1', 'Updated Successfully'); redirect('BookKeeping/daybook','refresh'); 

}

Comments

0

In your code

As I see your controller code posted in question, you haven't passed any value in variable $currentID which might be getting undefined, so please first try to var_dump your $currentID variable and check its value.

Do a test

Please try assigning a static id for the sake of functionality. Your static value will be passed to the method as an argument. Once you sure about static value is working, you can go ahead with finding out where is the issue in $currentID variable.

$data['currentID'] = $someValueFromDB; $this->load->view('some_view.php',$data); 

this way your value will be passed to view, make sure value is correctly passing or getting generated on view. You are passing data in right way at controller, no problem with that.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.