[eluser]cahva[/eluser]
You have atleast 2 things wrong. Your update method depends on url segment where id is the last but the form's action does not have that. Second, you are dealing with unique id so its pointless to loop through the result when theres only one row. Even if there were more than one result, the form would not work because the inputs have the same name and would only send the last row's values. Also try to keep the $this->db->.. off from your view. Fetch the result from your model in a controller and pass it to the view. Something like this(simplified):
Controller(2 methods, update and view)
Code:
function view_kandidaten($id=FALSE)
{
if (!$id)
{
return FALSE;
}
$data['id'] = $id;
$data['row'] = $this->admin_model->get_kandidaten($id);
$this->load->view('view_kandidaten',$data);
}
function update_kandidaten()
{
if (!$this->input->post('id'))
{
return FALSE;
}
$id = $this->input->post('id');
$data = array(
'functie' =>$this->input->post('functie'),
'kandidaatnr' => $this->input->post('kandidaatnr'),
'branche' => $this->input->post('branche'),
'regio' => $this->input->post('regio'),
'dienstverband' => $this->input->post('dienstverband'),
'beschrijving' => $this->input->post('beschrijving')
);
$this->admin_model->werknemer_update($id,$data);
redirect('admin/view_kandidaten/'.$id);
}
Model
Code:
function werknemer_update($id,$data)
{
$this->db->where('id', $id);
$this->db->update('kandidaten',$data);
return;
}
function get_kandidaten($id)
{
return $this->db->where('id',$id)->get('kandidaten')->row();
}
View (view_kandidaten)
Code:
<?php echo form_open('admin/update_kandidaten'); // Changed to plain form_open, you're not uploading files here ?>
<?php echo form_hidden('id',$id) ?>
<p>
<label for="functie">Functie:</label>
<input type="text" name="functie" id="functie" value="<?php echo $row->functie;?>" />
</p>
<p>
<label for="branche">Branche:</label>
<input type="text" name="branche" id="branche" value="<?php echo $row->branche;?>" />
</p>
<p>
<label for="regio">Regio:</label>
<input type="text" name="regio" id="regio" value="<?php echo $row->regio;?>" />
</p>
<p>
<label for="dienstverband">Dienstverband:</label>
<input type="text" name="dienstverband" id="dienstverband" value="<?php echo $row->dienstverband;?>" />
</p>
<p>
<label for="kandidaatnr">kandidaatnr:</label>
<input type="text" name="kandidaatnr" id="kandidaatnr" value="<?php echo $row->kandidaatnr;?>" />
</p>
<p><label for="beschrijving">Beschrijving:</label>
<textarea cols="40" rows="10" name="beschrijving" id="beschrijving"> <?php echo $row->beschrijving;?>
</textarea>
</p>
<?php echo form_submit('Aanpassen', 'Vacature aanpassen'); ?>
<?php echo form_close(); ?>
There can be errors in this as I did not test it naturally.