insert form values in table is not working in codeigniter

codeigniter insert not working
codeigniter insert query
insert batch codeigniter
insert query in codeigniter example
how to insert data in multiple table in codeigniter
insert data with form validation in codeigniter
how to insert data from one table to another in codeigniter
codeigniter data insert query

I am trying to insert form values in my table. I don't know the reason it's not posting values it's giving me error values cannot be null I am sure I have mentioned correct table values in my form can anyone check what mistake I have done

Here is my button:

<td><form action="<?php echo base_url();?>Dashboard/ReviewManagement" method="POST">
    <input type="hidden" name="topicid" value="<?php echo $proview->id;?>">
    <input type="hidden" name="courseid" value="<?php echo $proview->courseId;?>">
    <button type="submit" class="btn btn-xs btn-warning" >
        <span class="icon-ok"></span>
    </button>
</form></td>

Here is my controller:

public function ReviewManagement() {

    $username = $this->session->userdata('user_name');
    $data['userslist'] = $this->Dashboard_model->getUsers();

        $insert_data = array(
            'topicid' =>$this->input->post('topicid'),
            'stage' => $this->input->post('stage'),
            'allocatedresource' => $this->input->post('allocatedresource'),
            'status' => 1,
            'createdby' => $username,
            'createdon' => date('d/m/Y'),
            'expec' =>$this->input->post('expec')

        );

        $this->Dashboard_model->reviewmanagerInsert($insert_data);
        $this->load->view('template/header');
            $this->load->view('dashboard/reviewmanagement',$data);
            $this->load->view('template/footer'); 
        }

Here is my model:

    public function reviewmanagerInsert($data)
    {
   $this->db->insert('reviewmanager',$data); 
}

Here is my view:

  <form action="<?php echo base_url();?>Dashboard/ReviewManagement" method="post">
        <div class="form-row">
            <div class="col-md-3">Reviewer:</div>
            <div class="col-md-9"> 
                <select name="allocatedresource" class="form-control">
                   <option value="0">Select Reviewer</option>
                <?php foreach ($userslist as $users) { ?>
                    <option value="<?php echo $users->id; ?>"><?php echo $users->username; ?></option>
                <?php } ?>
            </select>
            </div>
        </div>
        <div class="form-row">
            <div class="col-md-3">Stage:</div>
            <div class="col-md-9"> 
                <select class="form-control col-md-8" name="stage" required="">
                    <option value="" selected="">Select Stage</option>
                    <option value="1">PB Review</option>
                    <option value="2">PB2 Review</option>
                    <option value="3">Alpha Review</option>
                    <option value="4">Beta Review</option>
                    <option value="5">Gamma Review</option>
                </select>
            </div>
        </div>

        <div class="form-row">
            <div class="col-md-3">Due Date:</div>
            <div class="col-md-9">
                <div class="input-group">
                    <div class="input-group-addon"><span class="icon-calendar-empty"></span></div>
                    <input type="text" name="expec" autocomplete="off" required="" class="datepicker form-control" value=""/>
                </div>
            </div>
        </div>
        <div class="form-row">
            <div class="col-md-8 col-md-offset-2">
                <button type="submit" class="btn btn-primary btn-block">Assign</button>             
            </div>
        </div>
    </form>

Got this error:

Column 'topicid' cannot be null

INSERT INTO `reviewmanager` 
            (`topicid`, `stage`, `allocatedresource`, 
            `status`, `createdby`, `createdon`, `expec`) 
    VALUES (NULL, NULL, NULL, 1, 'admin', '16/08/2018', NULL)

Can anyone help me what mistake I have done

Thanks in advance.

Just add below two input inside your form...

<input type="hidden" name="topicid" id="topic_id">
<input type="hidden" name="courseid" id="course_id">

db->insert Not Working, My solution was to set default values for each column in the data table that the insert function was operating on. Digg  After creating form in CodeIgniter framework one must learn to insert data into a database. Following steps explains you, how this operation can be done in easy way:-First, you must create a PHP page in View directory of CodeIgniter, in which a form is created using CodeIgniter’s syntax.

Use only one form with hidden fields and assign values to those hidden fields using jquery like

Your button view

<td>
    <div id="topicid" value="<?php echo $proview->id;?>"></div>
    <div id="courseid" value="<?php echo $proview->courseId;?>"></div>
    <button type="button" class="btn btn-xs btn-warning" >
        <span class="icon-ok" id="submit"></span>
    </button>
</td>

And in your main form add below hidden fields

<input type="hidden" name="topicid" id="topic_id">
<input type="hidden" name="courseid" id="course_id">

Then add below js to assign values

$(document).ready(function(){
    $("#submit").click(function(){
        var topicid = $("#topicid").val();
        var courseid = $("#courseid").val();
        $("#topic_id").val(topicid);
        $("#course_id").val(courseid);
    });
});

This answer is not tested though.

Active Record : CodeIgniter User Guide, CodeIgniter does not require that each database table be its own class file. Data; Inserting Data; Updating Data; Deleting Data; Method Chaining; Active  The value is not shown to the user; it’s the value that we’ll be able to access in our app’s code when the form is submitted. And since we will ultimately need the todos’ id values when writing the code to update their completion statuses in our database, we assign each todo’s id as the checkbox element’s value.

solved it like below

<td><form action="<?php echo base_url();?>Dashboard/ReviewManagement" method="POST">
                                                    <input type="hidden" name="topicid" value="<?php echo $proview->id;?>">
                                                    <input type="hidden" name="courseid" value="<?php echo $proview->courseId;?>">
                                                    <button type="submit" class="btn btn-xs btn-warning" >
                                                        <span class="icon-ok"></span>
                                                    </button>
                                                </form></td>

Changed second from like below

<form action="<?php echo base_url();?>Dashboard/ReviewManagementInsert" method="post">
                <div class="form-row">
                    <div class="col-md-3">Reviewer:</div>
                    <div class="col-md-9"> 
                        <select name="allocatedresource" class="form-control">
                           <option value="0">Select Reviewer</option>
                        <?php foreach ($userslist as $users) { ?>
                            <option value="<?php echo $users->username; ?>"><?php echo $users->username; ?></option>
                        <?php } ?>
                    </select>
                    </div>
                </div>

Controller Code1:

public function ReviewManagement() {

    if ($this->session->userdata('is_logged')) {
        if (!empty($this->input->post('topicid'))) {
            $id = $this->input->post('topicid');
            $data['userslist'] = $this->Dashboard_model->getUsers();
            $data['id'] = $this->input->post('topicid');
            $this->session->set_userdata('topicid', $data['id']);
            $this->load->view('template/header');
            $this->load->view('dashboard/reviewmanagement', $data);
            $this->load->view('template/footer');
        } elseif (!empty($this->session->userdata('topicid'))) {
            $id = $this->session->userdata('topicid');
            $data['userslist'] = $this->Dashboard_model->getUsers();
            $data['id'] = $this->session->userdata('gettopicdetails');
            $this->load->view('template/header');
            $this->load->view('dashboard/reviewmanagement', $data);
            $this->load->view('template/footer');
        } else {
            echo 'im else';
            die;
        }
    } else {
        $this->session->set_flashdata('error', 'Topic Id not captured.');
        redirect('Dashboard');
    }
}

Controller Code2

public function ReviewManagementInsert() {
    $topicid = $this->session->userdata('topicid');
    $username = $this->session->userdata('user_name');


    $insert_data = array(
        'topicid' => $topicid,
        'stage' => $this->input->post('stage'),
        'allocatedresource' => $this->input->post('allocatedresource'),
        'status' => 1,
        'createdby' => $username,
        'createdon' => date('d/m/Y'),
        'expec' => $this->input->post('expec')
    );

    $this->Dashboard_model->reviewmanagerInsert($insert_data);
    $this->load->view('template/header');
    $this->load->view('dashboard/reviewmanagement');
    $this->load->view('template/footer');
}

Query Builder Class, Uploading Class · Form Validation · FTP Class · Image Manipulation Class · Input Class CodeIgniter does not require that each database table be its own class file. Limiting or Counting Results; Query grouping; Inserting Data; Updating Data $status); // WHERE name = 'Joe' AND title = 'boss' AND status = 'active'. I am trying to insert data into database through Codeigniter, but I am not able to proceed. I have a database mydatabase with 5 tables training_assignment_id,assignment_name, assignment_description, recordings_required, and is_active. training_assignment_id is auto-increment. Controller-1 training.php

CodeIgniter Features : CodeIgniter User Guide, To input data into the database you need to create a form where you can input If it did not, the form is displayed, if it was submitted and passed all the rules, the You'll use the Active Record class to insert the information and use the input Each element corresponds with a column in the database table created earlier. Just Watch our live demo or download the delete_codeigniter.zip file from below link, extract files and include them in view, controller and model directory of your codeigniter framework as shown in the Read Me.txt file.-: See Also :-Insert Data using CodeIgniter Update Data in Database using CodeIgniter

CodeIgniter Insert Data into Database, After creating form in CodeIgniter framework one must learn to insert data into a CREATE DATABASE college; CREATE TABLE students( Student_id int(10) NOT NULL Its really amazing to work with codeigniter example. thanks a lot. CodeIgniter does not require that each database table be its own class file. It instead provides a more simplified interface. Beyond simplicity, a major benefit to using the Query Builder features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter.

CodeIgniter - Working with Database, CodeIgniter - Working with Database - Like any other framework, we need to interact We will use stud table to select, update, delete, and insert the data in stud table. Here, we are not passing any argument because everything is set in the public function update_student_view() { $this->load->helper('form'); $​roll_no  Like any other framework, we need to interact with the database very often and CodeIgniter makes this job easy for us. It provides rich set of functionalities to interact with database. In this section, we will understand how the CRUD (Create, Read, Update, Delete) functions work with CodeIgniter. We will use stud table to select, update

Comments
  • add these two hidden fields in your form : <input type="hidden" name="topicid" value="<?php echo $proview->id;?>"> <input type="hidden" name="courseid" value="<?php echo $proview->courseId;?>">
  • now i am getting stage cannot be null
  • why you have two forms ?
  • Are you using two forms?
  • no one for button reviewmanagement button there i am posting topicid and courseid while clicking on that button it will redirect to that page.and there i have one form that form values i am submitting into my table
  • I cannot see any of this field in your form... can you help me with it if i'm missing it?
  • no actually before some user has told me the same thing and i have added
  • It will work.. just try to place it properly inside your form and give value properly...
  • do not use 2 separate form try to place them in same form and check the variable of value is data not null...
  • what about the remaining values in my form
  • Keep your form as it is, just add <input type="hidden" name="topicid" id="topic_id"> <input type="hidden" name="courseid" id="course_id"> these two fields.