您好我为更改密码编写代码,但它不会更改表中的密码 但是制作0当前密码。所以我做什么。谢谢
这是我的模特
function changepassword() {
$this->db->select('id');
$this->db->where('username', $this->session->userdata('username'));
$this->db->where('password', $this->input->post('OldPassword'));
$query = $this->db->get('mau_user');
if ($query->num_rows() > 0) {
$row = $query->row();
if ($row->id === $this->session->userdata('id')) {
$data = array(
'password' => $this->input->post('password')
);
$this->db->where('username', $this->session->userdata('username'));
$this->db->where('password', $this->input->post('OldPassword'));
if ($this->db->update('mau_user', $data)) {
return "Password Changed Successfully";
答案 0 :(得分:0)
如果在db中将字段密码设置为整数,则默认值为0,因此您尝试更新它的值可能是无效的,您应该打印SQL并从那里启动调试程序....
答案 1 :(得分:0)
function edit_password()
{
$uderid = $this->session->userdata('user_id');
// update data
if($_POST)
{
if($this->input->post('old_password')!=''){
$this->form_validation->set_rules('old_password','Old password', 'trim|required|xss_clean|addslashes|encode_php_tags |callback_oldpass_check');
$this->form_validation->set_rules('new_password','New password', 'trim|required|xss_clean|addslashes|encode_php_tags|min_length['.PASS_MIN_LEN.']|md5');
$this->form_validation->set_rules('conf_password', 'Confirm password', 'trim|required|xss_clean|addslashes|encode_php_tags|min_length['.PASS_MIN_LEN.']|matches[new_password]|md5');
if($this->form_validation->run() == TRUE)
{
$data =array( 'password' => $this->input->post('conf_password'));
$this->main->update('users','user_id',$uderid,$data);
$this->change_password('Password updated successfully');
}
else{
$this->change_password();
}
}
else{
redirect(base_url().'user' , '301');
}
}
}
function oldpass_check($oldpass)
{
$user_id = $this->session->userdata('user_id');
$result = $this->main->check_oldpassword($oldpass,$user_id);
if($result ==0)
{
$this->form_validation->set_message('oldpass_check', "%s doesn't match.");
return FALSE ;
}
else
{
return TRUE ;
}
}
模型
function check_oldpassword($oldpass,$user_id)
{
$this->db->where('user_id', $user_id);
$this->db->where('password', md5($oldpass));
$query = $this->db->get('users'); //data table
return $query->num_rows();
}