1
我的代碼中沒有發生任何事情。沒有錯誤顯示,但密碼不變。點擊提交按鈕後,它只會重定向到password_view。如何檢查舊密碼並將其更新爲新密碼?
這裏是我的密碼查看:password_view.php
<?php echo form_open_multipart('password');?>
<div class="form-group">
<label class="control-label col-lg-2"> Old Password:</label>
<div class="col-lg-4">
<input class="form-control" name="oldPassword" placeholder="Old Password" type="password">
<span class="text-danger"><?php echo form_error('oldPassword'); ?></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"> New Password:</label>
<div class="col-lg-4">
<input class="form-control" name="newPassword" placeholder="New Password" type="password">
<span class="text-danger"><?php echo form_error('newPassword'); ?></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"> Re-type Password:</label>
<div class="col-lg-4">
<input class="form-control" name="renewPassword" placeholder="Re-type Password" type="password">
<span class="text-danger"><?php echo form_error('renewPassword'); ?></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-lg-2"></label>
<div class="col-lg-4">
<button type="submit" class="btn btn-primary btn-grad btn-rect">Submit</button>
<a href ="<?php echo base_url();?>index.php/main" class="btn btn-default btn-grad btn-rect">Cancel</a>
</div>
</div>
<?php echo form_close(); ?>
這裏是我的密碼控制器:password.php
public function index()
{
$this->form_validation->set_rules('oldPassword','Old Password','trim|required|min_length[5]|max_length[30]');
$this->form_validation->set_rules('newPassword','New Password','trim|required|min_length[5]|max_length[30]');
$this->form_validation->set_rules('renewPassword','Retype Password','trim|required|matches[newPassword]');
if($this->form_validation->run() == FALSE)
{
$this->load->view('password_view');
}
else
{
$this->load->model('account_model');
$this->load->view('password_view');
$query = $this->account_model->checkOldPassword($this->input->post('oldPassword'));
if($query)
{
$query = $this->account_model->saveNewPassword($this->input->post('newPassword'));
if($query)
{
$this->session->sess_destroy();
$data['error']='Password Change Successfully. Please login to Continue.';
$this->load->view('password_view',$data);
}
else
{
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Error. Please try again later!!!</div>');
redirect('account/editPassword');
}
}
}
}
這裏是我的密碼模式:account_model.php
public function checkOldPassword($oldPassword)
{
$this->db->select('AID');
$this->db->where('AID',$this->session->userdata('id'));
$this->db->where('Password',$this->input->post('oldPassword'));
$query=$this->db->get('tblaccount');
if($query->num_rows>0)
{
$row=$query->row();
if($oldPassword == $row->Password)
{
return true;
}
else
{
return false;
}
}
}
public function saveNewPassword($newPassword)
{
$data = array(
'Password' => $newPassword
);
$this->db->where('AID', $this->session->userdata('id'));
$this->db->where('Password',$this->input->post('oldPassword'));
$query = $this->db->update('tblaccount', $data);
if($query)
{
return true;
}
else
{
return false;
}
}
同樣,沒有發生。 –
請嘗試編輯答案我已在checkOldPassword方法中更改 –
請嘗試編輯答案後告訴我 –