On my codeigniter application, I have a list of users in which an admin can change the role of a user and update the user information. When editing a user the url is user/edit_user/1002 and the edit_user view is loaded. 1002 is the userid of the user.
When I submit the form and form_validation fails I reload the view but the problem is the last segment on the url with the userid is lost. So the sql queries used in the form fails. Is there a way I can reload the view with the errors and also keep the userid in the uri segment ? Given below is the code:
if ($this->form_validation->run() == FALSE) {
$userid = $this->uri->segment(3);
$this->db->where('userid', $userid);
$query = $this->db->get('user');
$row1 = $query->row();
$data = (array)$row1;
$sql = "SELECT userid, role_id FROM user_role WHERE userid = $userid ";// This sql fails
$ro = $this->db->query($sql);
$data['role_check'] = $ro->result();
$this->load->view('edit_user',$data);
}
Thanks in advance.
In view_user.php,
<tr>
<td><?php echo $loop->userid;?></td>
<td><?php echo $loop->name;?></td>
<td><a class="btn-small btn-info" href="<?php echo site_url(); ?>/user/edit_user/<?php echo $loop->userid;?>">Edit</td>
</tr>
The in controller user, I have used the code I posted first.