1

为什么我的密码没有插入数据库

模型:

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

    }
4

1 回答 1

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函数。您不需要转义数据,数据库库会为您完成。注意,您必须在脚本末尾加载视图

于 2012-06-12T01:00:50.553 回答