SupFrig
SupFrig

Reputation: 365

codeigniter - simple database insert failing without errors

I'm running a codeigniter application, and i can't get this simple insert to work well.

if(!$this->db->insert('myTable',$entry)){
    $p3 = 0;
}else{
    echo $this->db->last_query();
    var_dump($this->db->_error_message());
}

the debug in the "else" clause always show me an empty string for error message, and if i test the last_query in phpmyadmin, the insert work well.

But the insert isn't happening when i normally run the app, even if the "else" is launched, implying the request succeed.

any clue ?

UPDATE : exemple of $entry array :

$entry = array(
    'id' => '',
    'id_devis' => $current[0]->id,
    'metier' => $_POST[$i+1 . '_create_metier'],
    'days' => $_POST[$i+1 . '_create_daycount'],
    'price' => $_POST[$i+1 . '_create_price'],
    'cr_date' => date('Y-m-d H:i:s'),
    'user' => ''
);

$current is an extract of another table (using $this->db->get), and all the datas are fine, since i can insert them through the echo of last_query()

Upvotes: 1

Views: 1661

Answers (2)

SupFrig
SupFrig

Reputation: 365

Just found out the issue, there wasn't. a script was deleting the line i just inserted further in the code, the insert was successful. Thanks for your answers all

Upvotes: 1

RWC
RWC

Reputation: 5052

Put

error_reporting(E_ALL);
ini_set('display_errors', '1');

before the line with the insert. You should see an error message.

My guess is that you try to insert an illegal value for id. Possible reasons: - It should not be empty. - It can not be a string (ie. if the type is an integer)

Most of the time an id in the database is of type int and is an auto-increment field. If so, you should not try to insert an id. It will be created for you.

Upvotes: 1

Related Questions