This question already has an answer here:
I am inserting multiple images into database but getting such error
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0, 1) VALUES (Array, Array)' at line 1
INSERT INTO
CompleteProjectImage
(0, 1) VALUES (Array, Array)
I am holding list of selected image in the controller and passed it to my model.
Here is my model coding to insert into database.
public function create($projectDetails, $projectDescriptions, $projectImages){
$this->db->trans_begin();
$this->db->insert(self::$tblCompleteProject, $projectDetails);
$insert_id = $this->db->insert_id();
foreach ($projectDescriptions as $projectDescription) {
$insertDescription = array(
'project_id' => $insert_id,
'description' => $projectDescription,
);
}
$this->db->insert(self::$tblCompleteProjectDescription, $insertDescription);
foreach ($projectImages as $projectImage) {
$insertImage[] = array(
'project_id' => $insert_id,
'img_src' => $projectImage['img_src'],
);
}
$this->db->insert(self::$tblCompleteProjectImage, $insertImage); // Error inserting to this database
if ($this->db->trans_status() === FALSE)
{
$this->db->trans_rollback();
}
else
{
$this->db->trans_commit();
return ($this->db->affected_rows() != 1) ? false : true;
}
}
print_array($insertImage);
resulting :
Array
(
[0] => Array
(
[project_id] => 5
[img_src] => 594a7f9a79285.jpg
)
[1] => Array
(
[project_id] => 5
[img_src] => 594a7f9a792851.jpg
)
)
</div>