为什么我的密码没有插入数据库
型号:
function addUser($userData = NULL, $passwordHash)
{
$this->db->insert('users',$userData,$passwordHash);
return TRUE;
}
控制器:
public function addUser()
{
$data['pageTitle'] = 'GA Add User';
$this->load->view('_assets/header', $data);
$this->load->view('addUser', $data);
$this->load->view('_assets/footer');
$userData = array(
'fName' => $this->input->post('userFirstName', TRUE),
'lName' => $this->input->post('userLastName', TRUE),
'email' => $this->input->post('userEmail', TRUE)
);
$passwordHash = sha1($this->input->post('userPassword', TRUE));
$this->db->escape($userData);
$this->user_model->addUser($userData, $passwordHash);
}
答案 0 :(得分:2)
编辑:
function addUser($userData = NULL)
{
$this->db->insert('users',$userData);
return TRUE;
}
public function addUser()
{
$userData = array(
'fName' => $this->input->post('userFirstName', TRUE),
'lName' => $this->input->post('userLastName', TRUE),
'email' => $this->input->post('userEmail', TRUE),
'password'=>sha1($this->input->post('userPassword', TRUE))
);
$this->user_model->addUser($userData);
$data['pageTitle'] = 'GA Add User';
$this->load->view('_assets/header', $data);
$this->load->view('addUser', $data);
$this->load->view('_assets/footer');
}
在$ userdata数组中添加了密码以使其更清晰。并修改了addUser函数。您无需转义数据,DB库将为您执行此操作。注意您必须在脚本末尾加载视图