I would like to ask why the foreach does not insert record of all the data from $listname array but instead it only insert the last item from the array but if I do echo $fname inside foreach I could see the records. thanks
$last_id = $db_->lastInsertId();
foreach ($listname as $fname) {
$new_name->bindParam(':fname',fname);
$new_name->bindParam(':id',$last_id);
}
Either some of your code is missing or you’re just overwriting the parameters as you iterate through the for loop. You need to prepare the statement and, in your loop:
For each set of values you want to insert.