0

I'm using CodeIgniter, and I have to insert an ID in my table, but it doesn't work, I made this :

$this->db->insert('mytable', $data);
$id = $this->db->insert_id();
2
  • 2
    do you have the table configured to have a primary key that auto increments? Commented Mar 21, 2013 at 17:01
  • 1
    Can you update your question to include the value of $data. Commented Mar 21, 2013 at 17:26

2 Answers 2

2

it's fixed, I just forgot to use auto_increment in my ID column. Thank you ;)

Sign up to request clarification or add additional context in comments.

Comments

0

this works normally for me:

 function insert($data){

        $this->db->insert('users',$data);
        return $this->db->insert_id();

      }

you have to set your ID field to AUTO INCREMENT and be sure $data is an associative array, like:

$data = array(
     'db_field'=>'value'
);

Comments

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.