Diverse cose:
- Rimuovi la seconda istruzione prepare all'interno di
for
ciclo - Aggiungi parametri vincolati a
VALUES()
dell'istruzione sql - Indicizza le
$images
matrice confor
iteratore di loop o usaforeach
Vedi aggiustato for
ciclo:
$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();
}
In alternativa con foreach
loop (assumendo un array unidimensionale) :
$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();
}