在PHP MYSQL中将多个文件插入/上载到数据库表中的特定行

Problem: Only the last file upload inserted to the row (listing-amenities-safety-photos-id), which is supposed to be the entire photos selected during the upload.

HTML:

    <form action="#" method="post" enctype="multipart/form-data">
        <input name="upload[]" type="file" multiple="multiple" />
        <input type="submit" name="submit" value="UPLOAD" />
    </form>

PHP:

    <?php
if(isset($_POST['submit'])) {
    for ($i=0; $i<count($_FILES['upload']['name']); $i++) {
        $path = "../media/images/Listings/Set/";
        $ext = explode('.', basename( $_FILES['upload']['name'][$i]));
        $path = $path . md5(uniqid()) . "." . $ext[count($ext)-1]; 
        move_uploaded_file($_FILES['upload']['tmp_name'][$i], $path);           

    }           

    $quotequery = "INSERT INTO `listing-details` (`listing-amenities-safety-photos-id`) VALUES ('$path')";
    if (mysqli_query($conn, $quotequery) == TRUE) {

        echo "File uploaded.";
    } else {
        echo "Upload failed.". mysqli_error($conn);
    }

}

?>

Photo to show only one entry is inserted: Image as proof that only one entry from $path is inserted

Note: All photos were uploaded successfully to the designated path. However, I can't get mysql to insert all the files in my row. I'm thinking like an array might solve my problem, but I'm not really an array expert, or even PHP! So please, any answer that is helpful but "marked as duplicate" or "down vote" will be appreciated. Thanks

Move your database query inside your of loop. $path gets overwritten on each pass, so as it stands, it will only insert the last one.

<?php
if(isset($_POST['submit'])) {
    for ($i=0; $i<count($_FILES['upload']['name']); $i++) {
        $path = "../media/images/Listings/Set/";
        $ext = explode('.', basename( $_FILES['upload']['name'][$i]));
        $path = $path . md5(uniqid()) . "." . $ext[count($ext)-1];
        move_uploaded_file($_FILES['upload']['tmp_name'][$i], $path);

        $quotequery = "INSERT INTO `listing-details` (`listing-amenities-safety-photos-id`) VALUES ('$path')";
        if (mysqli_query($conn, $quotequery) == TRUE) {

            echo "File uploaded.";
        } else {
            echo "Upload failed.". mysqli_error($conn);
        }
    }
}

?>