Reputation: 117
i am trying to change password in database but it's not working..it printing the password correctly..but it's not save in the database..
Here is my controller:
public function resetpwd($user_id=NULL) {
//echo $user_id;
$this->load->helper('form');
$data['msg']=array();
if($this->input->post())
{
$user_id= $this->input->post('user_id');
//echo $id;
$this->LoginModel->resetpwd($this->input->post(),$user_id);
//redirect(base_url('resetpwd/'.$id));
}
$this->load->view('Admin/resetpwd',$data);
}
Here is my Model:
function resetpwd($post='',$user_id)
{
$data=array('password'=>$post['password']);
$this->db->where('user_id', $user_id);
$this->db->update('users', $data);
return true;
print_r($data);
}
Please help me how to do this
Thank you
Upvotes: 1
Views: 830
Reputation: 41
Apply this code
function resetpwd($post, $user_id)
{
$data=array('password'=>$post['password']);
$this->db->where('user_id', $user_id);
$this->db->update('users', $data);
return true;
}
Upvotes: 0
Reputation: 96
Please try this code.
function resetpwd($post=array(),$user_id)
You had passed post array to resetpwd function it is mendatory to get array into array variable. Change only one line it will be working.
Thank You.
Upvotes: 2
Reputation: 867
please try this code.
Controller :
class Adminuser extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('loginModel');
$this->load->helper('form');
}
public function resetpwd()
{
$data['msg']=array();
if($this->input->post())
{
$user_id= $this->input->post('user_id');
$this->loginModel->change_password($this->input->post('password'),$user_id);
}
$this->load->view('Admin/resetpwd',$data);
}
}
Your Model Function :
public function change_password($password,$user_id)
{
$data=array('password'=>$password);
$this->db->where('user_id', $user_id);
if($this->db->update('users', $data))
{
return true;
}
else{
return false;
}
}
Upvotes: 0
Reputation: 93
You can simply get the password in Model page using post method extract($_POST)
and you can get your new password like $data=array('password'=>$password)
Your Model is-
function resetpwd($user_id)
{
extract($_POST);
$data=array('password'=>$password);
$this->db->where('user_id', $user_id);
$this->db->update('users', $data);
return true;
//print_r($data);
}
Upvotes: 0