Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在CodeIgniter中尝试从控制器函数调用多个模型时出现MySQL错误1054_Php_Mysql_Codeigniter_Mysql Error 1054 - Fatal编程技术网

Php 在CodeIgniter中尝试从控制器函数调用多个模型时出现MySQL错误1054

Php 在CodeIgniter中尝试从控制器函数调用多个模型时出现MySQL错误1054,php,mysql,codeigniter,mysql-error-1054,Php,Mysql,Codeigniter,Mysql Error 1054,我想写一个函数,它将接受一系列字段并将不同的值输入到不同的数据库中。现在它只是两个独立的数据库条目,但我希望以后实现更多。我想在一个表中输入一个新Saint,然后,如果用户填写'ofRegion'字段,我想将其存储在另一个表中。当模型试图输入'ofRegion'的信息时,我的问题就出现了。我得到一个MySQL错误(1054),指出有一个未知列。我可以从MySQL错误中看出,它试图输入前一个条目中的所有信息以及新信息。如何清除旧信息?我甚至可以这样做,还是我需要为每个表输入多个模型 模型函数 pu

我想写一个函数,它将接受一系列字段并将不同的值输入到不同的数据库中。现在它只是两个独立的数据库条目,但我希望以后实现更多。我想在一个表中输入一个新Saint,然后,如果用户填写'ofRegion'字段,我想将其存储在另一个表中。当模型试图输入'ofRegion'的信息时,我的问题就出现了。我得到一个MySQL错误(1054),指出有一个未知列。我可以从MySQL错误中看出,它试图输入前一个条目中的所有信息以及新信息。如何清除旧信息?我甚至可以这样做,还是我需要为每个表输入多个模型

模型函数

public function input_saint($newSaintID)
{
    //grab values from post stream
    $this->saintID = $newSaintID;
    $this->active = 1;
    $this->nameFirst = $this->input->post('nameFirst');
    $this->nameLast = $this->input->post('nameLast');
    $this->gender = $this->input->post('gender');
    $this->martyr = $this->input->post('martyr');
    $this->nationality = $this->input->post('nationality');
    $this->feastMonth = $this->input->post('feastMonth');
    $this->feastDay = $this->input->post('feastDay');
    $this->about = $this->input->post('about');

    //insert information into the saint table
    $this->db->insert('saint_table', $this);
}

public function set_of_region($newSaintID)
{
    $this->saintID = $newSaintID;
    $this->ofRegion = $this->input->post('ofRegion');
    $this->db->insert('saint_of_region', $this);
}
控制器功能

public function saint_input()
{
    //Check if user is logged in, if they are not, send them to the login screen
    if($this->session->userdata('logged_in') == FALSE)
    {
        redirect('base/');
    }

    $this->load->library('form_validation');

    //load Saint model and get the nation list
    $this->load->model('saint_model');

    //Load the nation list
    $data['nationList'] = $this->saint_model->get_nations();

    if($this->form_validation->run('saint_input')==FALSE)
    {
        $this->load->view('std/top');
        $this->load->view('forms/saint_input', $data);
        $this->load->view('std/bottom');
    }
    else
    {
        //generate saintID
        $newSaintID = $this->saint_model->get_largest_saintID();
        $newSaintID++;

        $this->saint_model->input_saint($newSaintID);

        //if specified, record the ofRegion
        if($this->input->post('ofRegion') != NULL)
        {
            $this->saint_model->set_of_region($newSaintID);
        }

        //Send the user to this saint's single view page for review
        redirect('base/display_one_saint/'.$newSaintID);
    }
}

非常感谢您的时间和工作

这是因为您在插入数据之前使用$this作为数组来存储数据$这是对对象作为一个整体的引用,在对象上设置的任何属性都将保持不变,直到它们被取消设置为止。一种解决方案是将insert()函数更改为数组,如下所示:

public function set_of_region($newSaintID)
{
    $ins_arr['saintID'] = $newSaintID;
    $ins_arr['ofRegion'] = $this->input->post('ofRegion');
    $this->db->insert('saint_of_region', $ins_arr);
}