Reputation: 248
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
Upvotes: 0
Views: 70
Reputation: 1059
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.
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.
Upvotes: 0
Reputation: 1560
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');
}
Upvotes: 1
Reputation: 987
you are sending value in url change this
$id=$this->input->post('update');
To
$id=$this->uri->segment('3');
Upvotes: 2