Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6383575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:39:59+00:00 2026-05-25T02:39:59+00:00

I want to write a function which will take a series of fields and

  • 0

I want to write a function which will take a series of fields and input different values into a different databases. Right now it is only two separate database entries but I hope to implement more later. I want to input a new Saint into one table and then, if the user fills in the ‘ofRegion’ field, I want that to be stored in a different table. My problem comes about when the model tries to input the information for ‘ofRegion.’ I get a MySQL error ( 1054 ) stating there is an unknown column. I can see by the MySQL error that it is trying to input all the information from the previous entry as well as the new information. How do I clear the old information? Can I even do this or will I need multiple models for each table I want to enter information into?

Model Functions

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

Controller Function

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

Thank you very much for your time and work!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:40:00+00:00Added an answer on May 25, 2026 at 2:40 am

    That’s because you’re using $this as an array to store data before inserting it. $this is a reference to the object as a whole and any properties that you set on it will persist until they are unset. One solution is to change to an array for the insert() function as below:

    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);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a function validate() which will take some pattern or regular
I want to write a User-Defined function in SQL SERVER which will take a
I want to write a function in Python that returns different fixed values based
I want to write a function named size() which will accept either a file
I want to write a function that accepts a parameter which can be either
I'm trying to write up a function which will post data (and append the
I want to write a function which filters a list of numbers by removing
I want to create a function which will a number and the position of
I wrote a validation code for an input text field, which will take only
I want to write a function that takes an array of letters as an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.