0
早上好,有人可以幫我一下我有一個Iam未能掌握的小錯誤。我想更新/更改用戶電子郵件地址的密碼=例如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!";
}
}
}
}
?>
視圖
<?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>
<div id=」some」style=」position:relative;」><button type=」submit」 class=」btn btn-primary」><i class=」 icon-ok-sign icon-white」></i> Submit</button>
<?php
echo form_close();
?>
EDIT表結構
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 ;
也請向我們提供您的表結構,使更多的理解。 – Shreyas
@Shreyas我需要提供表結構嗎?當op提供了他的表結構 –
同意你的答案。 –