How to insert and update value in two different tables in codeigniter

Ask A Question

Login To post a question

I have two tables ‘booking’ and ‘schedule’ and when i insert values in ‘booking’ table i need to insert some value in another table and also update a field in second table

My controller

 public function booking(){
        $data = $_POST; 
        $check_seat = $this->Web_model->check_seat($data);
            $result =  NULL;
        } else {
            $booking =$this->Web_model->booking_details($data);
                $result =  $booking;
            } else {
                $result =  FALSE;
        print json_encode($result);

My model

 public function booking_details( $data){
                   $booking = array();
                   $bid ='TKT'.strtotime(date('m/d/Y H:i:s'));
                   $occupied = 'Occupied';
                   $busNumber = $data['busNumber'];
                   $bookingDate = $data['bookingDate'];
                   $seatLabel = $data['seatLabel'];
                   $passengerName = $data['passengerName'];
                   $paymentStatus = $data['paymentStatus'];
                   $agentId = $data['agentId'];
                   $booking = array(
                'ticketNumber'=>$bid ,
                'seatLabel'=>$seatLabel ,

            $this->db->insert('booking', $booking);
            $last_insert_id = $this->db->insert_id();

            $schedule = array(
                'ticketNumber'=>$bid ,                          


            $this->db->insert('schedule', $schedule);
            $seatStatus['seatStatus'] = $occupied;

            $query = $this->db->get_where('booking',array('id' => $last_insert_id));
                return $query->row();

check seat

public function check_seat($data){  
        return $query = $this->db->get('booking')->num_rows();  

From the above codes when i insert values i receive a FALSE result that means no value inserted but i don’t know where is the problem.

schedule table

booking table

For more info please click here

Have a question or need a custom quote?