dongyan1993 2013-09-25 07:56
浏览 30
已采纳

删除密码而不是重置密码

Morning all , may someone please assist me I have one small error that Iam failing to grasp. I would like to update/change password where users email = for example 123@gmail. however when i input the new password it removes the old and leaves the field blank.

  **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!";
      }
    }


}
}


?>

view

<?php
 echo form_open(base_url()."index.php/my_account/change_password")?>
 <?php echo validation_errors();
   ?>
 <table class=”table table-bordered”>
  <tbody>
  <tr>
<td><small><?php echo 'Old Password:';?></small></td>
<td><?php echo form_password("cur_password");?></td>
</tr>
<tr>
<td><small><?php echo 'New Password:';?></small></td>
<td><?php echo form_password("new_password");?></td>
</tr>
  <tr>
  <td><small><?php echo 'Confirm Password:';?></small></td>
  <td><?php echo form_password("con_password");?></td>
  </tr>
  </tbody>
   </table>
 &nbsp;&nbsp;<div id=”some”style=”position:relative;”><button type=”submit” class=”btn    btn-primary”><i class=” icon-ok-sign icon-white”></i>&nbsp;Submit</button>
<?php
echo form_close();
 ?>

EDIT Table structure

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 ;
  • 写回答

1条回答 默认 最新

  • duanping2005 2013-09-25 08:06
    关注

    The problem is you are not making correct array to update the password instead you are updating the generated md5 string to

    $fixed_password ='password'; wrong

    Try this one

    $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)
    

    See Active Record Reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效