0
從控制器的功能不止一個模型調用我想寫這將採取一系列域和輸入不同的值到不同的數據庫的函數1054。目前它只有兩個獨立的數據庫條目,但我希望稍後再實施。我想輸入一個新的Saint到一個表中,然後,如果用戶填入'ofRegion'字段,我希望將它存儲在不同的表中。我的問題出現在模型嘗試輸入'ofRegion'的信息時。我得到一個MySQL錯誤(1054),說明有一個未知的列。我可以看到MySQL錯誤,它正在嘗試輸入以前條目的所有信息以及新信息。我如何清除舊信息?我可以做到這一點嗎?或者我需要多個模型用於每個我想輸入信息的表格?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);
}
}
非常感謝您的時間和努力!