尝试将表单数据插入到数据库但错误

时间:2013-04-08 12:38:28

标签: codeigniter

两个错误

错误1

A PHP Error was encountered

Severity: Notice

Message: Use of undefined constant model_users - assumed 'model_users'

Filename: controllers/main.php

Line Number: 110

错误2

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Main::$add_database

Filename: core/Model.php

Line Number: 51

控制器

if ($this->form_validation->run() == TRUE)
{
    $this->load->model(model_users);          //Line 110
    $this->model_users->add_database;
}else{
    $this->load->view('signup');
}

模型

public function add_database() {


$usersdata = array (
                'email'     =>  $this->input->post('email'),
                'password'  =>  md5($this->input->post('password')),
);

$regdetails = array (
                'full_name'         =>  $this->input->post('full_name'),
                'gender'            =>  $this->input->post('gender'),
                'dob'               =>  $this->input->post('dob'),
                'address'           =>  $this->input->post('address'),
                'city'              =>  $this->input->post('city'),
                'state'             =>  $this->input->post('state'),
                'country'           =>  $this->input->post('country'),
                'pin'               =>  $this->input->post('zip'),
                'alternative_email' =>  $this->input->post('alt_email'),
                'phone'             =>  $this->input->post('phone'),
                'mobile'            =>  $this->input->post('mobile'),
);


    $query = $this->db->insert('users',$usersdata);
    $this->db->insert('tbl_studentreg',$regdetails);
}

我可以知道如何修复它吗?在上面提到的代码中没有未来的错误。提前谢谢..

3 个答案:

答案 0 :(得分:0)

您错过了" ..将您的模型名称传递为字符串...

 $this->load->model("model_users");   

docs here

第二个错误,

您需要添加(),因为您正在调用名为add_database

的函数
 $this->model_users->add_database();

答案 1 :(得分:0)

加载模型的语法错误。只需将模型的名称指定为字符串即可 它会是这样的。

$this->load->model("model_users"); 

如果再次出现错误,请检查您为模型指定的名称 你的行可能是这样的。

class Model_users extends CI_Model{

}

答案 2 :(得分:0)

您是否已在config / autoload.php中加载数据库库

$autoload['libraries'] = array('database');