I am new in Codeigniter, but when I try to update table value I am getting no error, but data not updated in mysql database. Please someone help.
here is my controller code:
public function changePassword()
{
$this->load->model('User_model');
$this->logged_in();
$data['title'] = "Change Password";
$this->form_validation->set_rules('oldpass', 'Current Password', 'callback_password_check');
$this->form_validation->set_rules('newpass', 'New Password', 'required');
$this->form_validation->set_rules('passconf', 'Confirm Password', 'required|matches[newpass]');
$this->form_validation->set_error_delimiters('<div class="error">','</div>');
if($this->form_validation->run() == false){
$user= $this->session->userdata('user');
$data['user'] = $user;
$this->load->view('header', $data);
$this->load->view('change_password', $data);
$this->load->view('footer', $data);
}else{
$id = $this->session->userdata('id');
$newpass = $this->input->post('newpass');
$this->User_model->update_user($id, array('password' => password_hash($newpass, PASSWORD_BCRYPT))) ;
redirect('User/logout');
}
}
public function password_check($oldpass)
{
$id = $this->session->userdata('id');
$user = $this->User_model->get_user($id);
if(password_verify($oldpass, $user['password']) == false){
//echo '<pre>'; var_dump($user); echo '</pre>';
//die();
$this->form_validation->set_message('password_check', 'The {field} does not match');
return false;
}
return true;
}
here is my model:
public function get_user($id)
{
$this->db->where('id', $id);
$query = $this->db->get('register');
return $row = $this->db->get('register')->row_array();
}
public function update_user($id, $sessArray)
{
$id = $this->session->userdata('id');
//echo '<pre>'; var_dump($id); echo '</pre>';
//die();
$this->db->set($sessArray);
$this->db->where('id', $id);
$this->db->update('register');
}
here is my view page:
<div class="row justify-content-center" style="margin-top: 50px;">
<div class="col-4">
<h1><?php echo $title ?></h1>
<?php echo form_open('User/changePassword', array('id' => 'passwordForm'))?>
<div class="form-group">
<input type="password" name="oldpass" id="oldpass" class="form-control" placeholder="Current Password" />
<?php echo form_error('oldpass', '<div class="error">', '</div>')?>
</div>
<div class="form-group">
<input type="password" name="newpass" id="newpass" class="form-control" placeholder="New Password" />
<?php echo form_error('newpass', '<div class="error">', '</div>')?>
</div>
<div class="form-group">
<input type="password" name="passconf" id="passconf" class="form-control" placeholder="Confirm Password" />
<?php echo form_error('passconf', '<div class="error">', '</div>')?>
</div>
<div class="form-group">
<button type="submit" class="btn btn-success">Change Password</button>
</div>
<?php echo form_close(); ?>
</div>
</div>