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 6017235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:05:57+00:00 2026-05-23T03:05:57+00:00

Hello I just started CodeIgniter . I am having problem in loading view. My

  • 0

Hello I just started CodeIgniter. I am having problem in loading view.

My scenrio is I am creating a sample add form. After submit it goes to controller and insert entries in database. I want if the database operation is successfull it again comes to same view having again some values. And on the basis of those values I am showing some particular rows informing user about insertion operation. My function in controller looks like

public function add_user()
{
    $this->load->view('add_user');
    $post=$this->input->post();
    if(isset($post['name']))
    {
        $data=array(
        'name'=>$post['name'],
        'designation'=>$post['designation']
        );
        if($this->db->insert('user',$data))
        $result['update']=true;
        else
        $result['update']=false;
        $this->load->view('add_user',$result);
    }

}

And my view looks like

    <h1 align="center">Add User</h1>
    <table border="0" cellpadding="2" cellspacing="2" align="center">
        <?php
        if(isset($update))
        {
            if($update)
            {
                ?>
                <tr bgcolor="#00FF00">
                    <td>Record Added Successfully</td>
                </tr>
            <?php
            }
            else
            {
                ?>
                <tr bgcolor="#FF0000">
                    <td>Insertion Operation Failed</td>
                </tr>
            <?php
            }   
        }
        ?>
        <?php echo(form_open('first/add_user'));?>
            <tr>
                <td>Name</td>
                <td><input type="text" name="name" /></td>
            </tr>
            <tr>
                <td>Designation</td>
                <td>
                    <select name="designation">
                        <option value="Junior PHP Developer">Junior PHP Developer</option>
                        <option value="Senior PHP Developer">Senior PHP Developer</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" name="submit" value="Add User" />
                </td>
            </tr>   
        </form>
    </table>

Now What I want that if insertion operation is successfull I am sending true value to view and if not I am sending false value. And on the basis of this value I am showing some rows. I am loading the view two times as per I understood the logic. Because first time it loads the form and second time It loads view with some value of true or false. But what happens that after it reloads there are two forms. I know this problem is due to double loading of my view. i want to ask if there is another way of sending values after database operation to view?

  • 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-23T03:05:58+00:00Added an answer on May 23, 2026 at 3:05 am

    Simply load your view once:

    public function add_user()
    {
      $post=$this->input->post();
      $result = array();
      if(isset($post['name']))
      {
          $data=array(
           'name'=>$post['name'],
           'designation'=>$post['designation']
          );
          if($this->db->insert('user',$data))
          $result['update']=true;
          else
          $result['update']=false;
      }
      $this->load->view('add_user',$result);
    }
    

    By the way your code is a bit messy, work on it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello i have just started learning mvc2 and im having a problem with the
Hello I just started working with CodeIgniter framework. My current directory structure is Demo(Project
I have just started the Hello World App using Blackberry Eclipse Plugin. I have
I have just started with Android with the usual Hello World project template in
I have just started learning Javascript. I want Hello World! to be written to
I just started learning C++ and I wrote this sample program from the text
I just started reading Oreilly's XMPP The Definitive Guide and for the hello world,
I have just put the first step in android,and just started with hello android
I've just started playing with IoC containers and therefore chosed Ninject. After several hours
I am very new to Android application development. Just started Hello world android application

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.