codeigniter INSERT query is correct and executed but no insert is performed codeigniter INSERT query is correct and executed but no insert is performed codeigniter codeigniter

codeigniter INSERT query is correct and executed but no insert is performed


i think you are looping wrong:

$sql .= "('".$element."','1'),";

this produces (value,1), (value, 1) , (value, 1)

while you need

(value,value,value)

ma che te lo dico a fare poi :P

so your query is:

INSERT INTO table(ID,id_activity,id_cont) VALUES (somenthin,1), (somenthing,1) etc ..

and you need instead

INSERT INTO table(ID,id_activity,id_cont) VALUES (value,value,value) ;

you can try this:

$sql = "INSERT INTO table(id_activity,id_cont) VALUES (".implode(',',$elements)."); ";if (!$this->db->query($sql)) {    echo "FALSE";}else {    echo "TRUE";}echo $this->db->last_query();

IN CASE you are trying making an INSERT BATCH check the Codeigniter documentation it says:

 $data = array(   array(      'title' => 'My title' ,      'name' => 'My Name' ,      'date' => 'My date'   ),   array(      'title' => 'Another title' ,      'name' => 'Another Name' ,      'date' => 'Another date'   ));$this->db->insert_batch('mytable', $data);// Produces: INSERT INTO mytable (title, name, date) VALUES ('My title', 'My name', 'My date'), ('Another title', 'Another name', 'Another date')


replace the code :

$sql = "INSERT INTO table(id_activity,id_cont) VALUES";foreach($elements as $element) {    $sql .= "('".$element."','1'),";}

With the code:

$sql = "INSERT INTO table(ID,id_activity,id_cont) VALUES";foreach($elements as $element) {    $sql .= " ('','".$element."','1'),";}