This blog will explain to you how to add more than one images at a single time in MySQL database using PHP.

I’m assuming that you created a database and table for multipleimages (Fields: Id, Images).

Step 1. For this, I created a file in C:\xampp\htdocs\ and give an appropriate name to that folder. I created the addmultipleimages.php file. Also, create one folder with name "images" in correspondant folder where uploaded images will be store.

addmultipleimages.php 

<?php

$con = new mysqli("localhost", "root", "", "demo") or die(mysqli_error($con));

?>    

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title> Multiple Images Demo </title>

    <style>

        input[type=text],input[type=email],input[type=password]{

            width:100% !important;

        }

        table{

            border: 1px solid rgb(202,207,210);

        }

        form {

            margin: 10% auto 0;

        }

    </style>

</head>

<body>

    <form method="post" enctype="multipart/form-data">

        <center><h1>Multiple Images Demo</h1></center>

        <table align="center" border="0">

            <tr>

                <td>Images:</td>

                <td><input type="file" name="txtimg[]" multiple="multiple"></td>

            </tr>

            <tr>

                <td colspan="2" align="center"><input type="submit" value="Insert" name="btninsert" style="margin-top:10px;"></td>

            </tr>

        </table>

    </form>

    <?php

        if (isset($_REQUEST["btninsert"]))

        {

            for ($i = 0; $i < count($_FILES['txtimg']['name']); $i++)

            {

                move_uploaded_file($_FILES["txtimg"]["tmp_name"][$i], "images/" . $_FILES["txtimg"]["name"][$i]);

                $image = $_FILES["txtimg"]["name"][$i];

        

                $res = $con->query("insert into multipleimages(Images) values('" . $image . "')") or die(mysqli_error($con));

            }

    

            if ($res == TRUE)

            {

                echo "<script>alert('Multiple images added successfully..!!')</script>";

            }

            else

            {

                echo "<script>alert('Error while adding data..!!')</script>";

            }

        }

    ?>

   </body>

</html>

Input type file has property multiple="multiple" which will use to select multiple images from file dialouge.

Output

Here, in file control at a single time, you can select more than one images. After selecting images when you click on insert button selected images added into the database that you can see in the above images.

If you have any query, you can ask in the comment box. Thank you :)