Skip to content
Advertisement

Multiple images not inserted into mysql database

I am unable to insert multiple images into database. When I am inserting the images, only one image is inserted. not all inserted. I have shown here the form with php insert code.I have not found where the problem is. Plz help.

JavaScript

This is php code:

JavaScript

I am able to upload only the last image that is uploaded last. All images are not inserted into phpmyadmin database.

Advertisement

Answer

As already noted your loop was hitting the redirect on the first iteration and then sending you off before all the images could be saved and logged. The use of prepared statements can be done in such a way that you do the preparation and binding of variables just once but execute many times until the statement is closed.

JavaScript

Ok – The following was done as a full, end-to-end test and works ok ~ you will need to edit the $dir variable to suit

JavaScript

Snippet from db after running and uploading a few images at once

JavaScript
Advertisement