开发者

"Undefined variable: array" when creating registration form

开发者 https://www.devze.com 2023-03-05 07:09 出处:网络
I\'m folowing these tutorials http://www.youtube.com/watch?v=wuvq941piDI&feature=relmfu when creating registration form for my website.

I'm folowing these tutorials http://www.youtube.com/watch?v=wuvq941piDI&feature=relmfu when creating registration form for my website. I noticed that sometimes it 开发者_如何转开发is not shown in tutorial what changes need to be made to that everything would work fine. So far I don't think I made any typo mistakes because I double checked everything. But I still get the problem:

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: array

Filename: models/user_model.php

Line Number: 10

Here's user_model.php (model)

$

function register_user($username, $password, $name, $email)
{
    $sha1_password = sha1($password);

    $query_str = "INSERT INTO tbl_user (username, password, name, email) VALUES (?, ?, ?, ?)";

    $this->db->query($query_str, $array($username, $sha1_password, $name, $email));

}   

}

and user.php (controller)

function index()
{
    $this->register();
}

function register()
{
    $this->load->library('form_validation');

    $this->form_validation->set_rules('username', 'Username', 'trim|required|alpha_numeric|min_length[6]|xss_clean');
    $this->form_validation->set_rules('name', 'Name', 'trim|required|alpha_numeric|min_length[6]|xss_clean');
    $this->form_validation->set_rules('email', 'Email Address', 'trim|required|min_length[6]|xss_clean|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'trim|required|alpha_numeric|min_length[6]|xss_clean');
    $this->form_validation->set_rules('password_conf', 'Password Confirmation', 'trim|required|alpha_numeric|min_length[6]|matches[password]|xss_clean');





    if ($this->form_validation->run() ==FALSE)
    {
        $this->load->view('view_register');         //errors
    }
    else
    {
        $username = $this->input->post('username');
        $name = $this->input->post('name');
        $password = $this->input->post('password');
        $email = $this->input->post('email');

        $this->load->model('User_model');
        $this->User_model->register_user($username, $password, $name, $email);
    }



}

}

I'm not pasting view here because I don't think it is useful right now. I also always delete function with "parent::". It always causes me troubles and I don't know how to use it, so I just paste the needed information there, where it is needed. It worked fine so far. I am newbie, so this problem might be simple or maybe I just shouldn't have deleted that parent::.


You've got $array($username, $password...) where it should be array($username, $password...). There's an extra $, third line of your first function.


you have a typo on this line in user_model.php

$this->db->query($query_str, $array($username, $sha1_password, $name, $email));

should be

$this->db->query($query_str, array($username, $sha1_password, $name, $email));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号