Varias cosas:
- Elimine la segunda declaración de preparación dentro de
for
bucle - Agregue parámetros enlazados en
VALUES()
de sentencia sql - Indexar las
$images
matriz confor
iterador de bucle o useforeach
Ver for
bucle:
$stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image)
VALUES (:category_id, :dir_image)");
$stmt->bindParam(":category_id" ,$lastId);
$stmt->bindParam(":dir_image", $image);
for ($i = 0; $i < count($images); $i++){
$image = $images[$i];
$stmt->execute();
}
Alternativamente con foreach
bucle (asumiendo una matriz unidimensional) :
$stmt = $this->db->prepare("INSERT INTO images (category_id, dir_image)
VALUES (:category_id, :dir_image)");
$stmt->bindParam(":category_id", $lastId);
$stmt->bindParam(":dir_image", $item);
foreach ($images as $item){
$stmt->execute();
}