0

SELECT NEXT VALUE FOR contract_seq

//it will return next value of sequence 1, 2, 3 etc..i need to insert this sequence number to the database table.Using codeigniter i want to insert sequence number to database table

INSERT dbtest.contract (Contract_no) VALUES (NEXT VALUE FOR pestcontrol.contract_seq) // error Invalid object name 'pestcontrol.contract_seq'.
1
  • i have created sequence name contract_seq Commented Jun 20, 2019 at 15:20

1 Answer 1

0

I think you haven't returned inserted id in model.Try this :

public function save_contract($data){ 
         $insert_id = 0;
       if($this->db->insert("contract", $data)){
        $insert_id = $this->db->insert_id();
        }
        return $insert_id;
    }

CONTROLLER

public function contract_submitted() {

   $data = array(
       'line_of_business_id' => $this->input->post('busi'),
       'Contact_name' => $this->input->post('name')
     );
       $lastID= $this->modal_create_contract->save_contract($data);
       if(!$lastID){
        //Show Error 
        }
       $data['last_id']=$lastID;
       $this->load->view('contract',$data);
    }
Sign up to request clarification or add additional context in comments.

7 Comments

how to view this id in view page?inside ajax success
You need to call this method contract_submitted() (URL: base_url()."/controllername/contract_submitted") in ajax and replace $this->load->view('contract',$data); to echo json_encode($data); return;. By using this you will get $data array in ajax success.
Is your ajax call calling the contract_submitted method of the controller?
when using last inserted id, if two system are trying to insert at a same time means then i will get wrong id right??
@becool, no, the insert_id function returns the last id inserted on THAT connection only.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.