Php 删除密码而不是重置密码

Php 删除密码而不是重置密码,php,mysql,codeigniter,wamp,Php,Mysql,Codeigniter,Wamp,早上好,请有人帮助我,我有一个小错误,我没有抓住。我想更新/更改密码,其中用户email=例如123@gmail. 但是,当我输入新密码时,它会删除旧密码,并将字段留空 **Controller** <?php class My_account extends CI_Controller{ public function index(){ $this->load->view("vChangePassword"); } public function

早上好,请有人帮助我,我有一个小错误,我没有抓住。我想更新/更改密码,其中用户email=例如123@gmail. 但是,当我输入新密码时,它会删除旧密码,并将字段留空

  **Controller**
       <?php
 class My_account extends CI_Controller{
public function index(){
    $this->load->view("vChangePassword");
}

public function change_password()
{

    $this->load->library('form_validation');

    $this->form_validation->set_rules('cur_password','Current Password','required');
   $this->form_validation->set_rules('new_password','New Password','required');
   $this->form_validation->set_rules('con_password','Confirm Password', 'required[matches[new_password]');
    if ($this->form_validation->run()!= true){

        $this->load->view("vChangePassword");
    }else {
        $sql = $this->db->select("*")->from('users')->where('email',$this->session->userdata('email') )->get();
    foreach($sql->result() as $my_info)
    {
        $db_password = $my_info->password;
        $email = $my_info->email; 
    }
      if(md5($this->input->post('cur_password'))== $db_password){
        $fixed_password = mysql_real_escape_string(md5($this->input->post('new_password')));
       // $update = $this->db->query("Update 'users' SET 'password' = '$fixed_password' WHERE 'id' = '$db_id'") or die(mysql_error());
       $fixed_password ='password';
      // $fixed_password = md5($this->input->post('new_password'));
       $this->db->where('email', $email)->update('users' ,$fixed_password );
      // $update = $this->db->query("Update 'users' SET 'password' = '$fixed_password' WHERE 'id'= '$db_id'")or die(mysql_error());
      echo "Password has been updated!" ;  

      }
      else {
          echo "Password is incorrect!";
      }
    }


}
}


?>

问题是您没有生成正确的数组来更新密码,而是将生成的md5字符串更新为

$fixed_password='password';错

试试这个

$fixed_password = mysql_real_escape_string(md5($this->input->post('new_password')));
$data = array('password' => $fixed_password);

$this->db->where('email', $email);
$this->db->update('users', $data)

请同时向我们提供您的表格结构,以使我们更容易理解。@Shreyas我真的需要提供表格结构吗?当op提供了他的表格结构时,请同意您的回答。
CREATE TABLE IF NOT EXISTS users (
    id INT (11) NOT NULL AUTO_INCREMENT,
    email VARCHAR (255) NOT NULL,
    `password` VARCHAR (255) NOT NULL,
    `status` VARCHAR (255) NOT NULL,
    `Level` INT (11) NOT NULL,
    username VARCHAR (255) NOT NULL,
     avatar TEXT NOT NULL,
     signup_date INT (10) NOT NULL,
     PRIMARY KEY (id) >
  ) ENGINE = INNODB DEFAULT CHARSET = latin1 AUTO_INCREMENT = 9 ;
$fixed_password = mysql_real_escape_string(md5($this->input->post('new_password')));
$data = array('password' => $fixed_password);

$this->db->where('email', $email);
$this->db->update('users', $data)