I use codeigniter3.0.0 version, when i run the project i get this error plz tell me how i fix this error.

Error Number: 1048
Column 'no_of_people' cannot be null

INSERT INTO reservation (no_of_people) VALUES (NULL)

Filename: C:/xampp/htdocs/book/application/models/Books_model.php

Line Number: 26

My model code is

class Books_model extends CI_Model{



public function __construct(){

    $this->load->database();


}

public function get_restaurants()
{
    $sql = "SELECT restaurant_id, names FROM restaurants ";
    $query = $this->db->query( $sql );
    return $query->result();

}

public function insert_into_db()
{
   $people =$this->input->post('no_of_people');
   return $this->db->insert('reservation', array('no_of_people'=>$people));

}
}

Controller

<?php error_reporting(E_ALL); ini_set('display_errors', 1);
class Booking_Controller extends CI_Controller{

    public function __construct(){


        parent::__construct();
        $this->load->model('Books_model');

    }


public function view()
{





    $data['result']=$this->Books_model->get_restaurants();

    $this->load->helper(array('form','url'));
    $this->load->view('restaurants/booking',$data);

    $this->Books_model->insert_into_db();

}
}

view file

<form action="<?php echo base_url();?>booking_controller/view" method="POST">

                <table>
                    <tr>
                        <td>number of people</td>
                <td>number of people = <input type = 'text' name='no_of_people'></td>
                    </tr>
                <tr>
                    <td><input type='submit' value="Submit"></td>

                </tr>
            </table>
            </form>


            When i applied null constraint on no_of_people column than only null value store in database Plz guide me where i did mistake...thanx

Recommended Answers

All 3 Replies

Try this:

public function insert_into_db()
{
    if( $this->db->insert('reservation', $this->input->post('no_of_poeple', TRUE)) ){
        return TRUE;
    }else{
        return FALSE;
    }
}

Inserting data into the database

Did you have a question to ask other than repeating the title of that two year old post? Best to start a new thread if you do (rather than hijacking an old one) and explain fully what the problem you are having is so that others are in a position to offer some help. Thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.