我已經使用Codeignitor編寫了用於更新用戶詳細信息的代碼,但是當點擊更新按鈕用戶帳戶頁面時沒有任何事情發生。誰能幫我找到問題和解決方案通過如下因素我下面的代碼來解決:更新Codeigniter中的用戶詳細信息
控制器:
public function update_userdetail() {
// Load form helper and validation library
$this->load->helper('form');
$this->load->library('form_validation');
// Update field validation
$this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[4]|is_unique[users.username]', array('is_unique' => 'This username already exists.'));
$this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|is_unique[users.email]', array('is_unique' => 'This email already exists.'));
if($this->form_validation->run() == false) {
redirect('user/account');
} else {
// Set variable from Form
$user_id = $this->input->post('user_id');
$username = $this->input->post('username');
$email = $this->input->post('email');
if($this->user_model->update_user($user_id, $username, $email)) {
$this->session->set_flashdata('notice','<div class="success">Your details updated Successfully!</div>');
redirect('user/account');
} else {
$this->session->set_flashdata('msg', '<div class="error">Problem with update your detail!</div>');
redirect('user/account');
}
}
}
型號:
public function update_user($username, $email, $user_id) {
$data = array (
'username' => $username,
'email' => $email,
'updated_at' => date('Y-m-j H:i:s'),
);
$this->db->where('id', $user_id);
$this->db->update('users', $data);
return;
}
形式:
<?php
$username = ($this->session->userdata['username']);
$email = ($this->session->userdata['email']);
$user_id = ($this->session->userdata['user_id']);
?>
<h3>Update detail</h3>
<?php echo $this->session->flashdata('msg'); ?>
<?php echo form_open(); ?>
<input type="text" id="user_id" name="user_id" value="<?php echo $user_id; ?>">
<div>
<input type="text" id="username" name="username" placeholder="Username" value="<?php echo $username; ?>">
<small class="error-text"><?php echo form_error('username'); ?></small>
</div>
<div>
<input type="email" id="email" name="email" placeholder="Enter your email" value="<?php echo $email; ?>">
<small class="error-text"><?php echo form_error('email'); ?></small>
</div>
<div><?php echo form_submit('submit', 'Submit'); ?></div>
<?php echo form_close(); ?>
cehck此鏈接:https://ellislab.com/codeigniter/user-guide/helpers/form_helper。 html –
ist all check'print_r($ _ POST);'獲取值還是不是? – devpro
@PathikVejani是的,我做了,但無法找到問題出在哪裏:( –