How to show multiple images into a html via file path saved into a MySQL DB?

Currently i’m working on making a site that uploads multiple image files and shows the images uploaded individually according to Project ID in another page

for now i made a MySQL DB and have been using it to register the “projects” and save the file path in another table while the php script is responsible for uploading the file path of each image directly onto the db, but for now i’m a little confused in how to make the images show up individually while pulling the file path from the DB

Here’s my current code for now

SQL

CREATE TABLE projetos(
id INT(11) auto_increment PRIMARY KEY,
nome TEXT,
turma TEXT(10),
camArquivo TEXT
);
                
CREATE TABLE imagens (
id INT(11) auto_increment primary key,
id_projeto INT (11),
camArquivo TEXT,
FOREIGN KEY (id_projeto) REFERENCES projetos(id)
);

PHP

inserir_db.php

<?php
include_once 'connect.php';

//Saving text inputs into PHP Variables
$nome = isset($_POST['nome']) ? $_POST['nome'] : null;
$turma = isset($_POST['turma']) ? $_POST['turma'] : null;

//Creating the condition variables for the upload
$uploadimgOK = 0;
$uploadsuccess = 0;

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //
    $target_dir = 'uploads/';
    $allowTypes = array('jpg', 'png', 'jpeg', 'gif');

    $fileNames = array_filter($_FILES['files']['name']);

    // Uploading text fields into the table so that it generates the ID used for 
    // registering each image into the Images Table

    $stmt = $pdo->prepare('INSERT INTO projetos (nome, turma) VALUES (:nome, :turma)');
    $stmt->execute([':nome' => $nome, ':turma' => $turma ]);

    $id = $pdo->lastInsertId();
    
    if (!empty($fileNames)) {
        foreach ($fileNames as $key => $value) {
            $fileName = basename($_FILES['files']['name'][$key]);
            $targetFilePath = $target_dir . $fileName;
            
            $fileType = pathinfo($targetFilePath, PATHINFO_EXTENSION);

            //Verifying the file extension so that it is really a image file

            if (in_array($fileType, $allowTypes)) {
                $uploadimgOK= 1;
            }else{
                $uploadimgOK= 0;
            }
            
            // Uploading image file path into MySQL
            
            if ($uploadimgOK == 1) {
                $stmt = $pdo->prepare('INSERT INTO imagens(id_projeto, camArquivo) VALUES (:id, :arquivo)');
                $stmt->execute([':id' => $id, ':arquivo' => $targetFilePath]);    
            }else{
                echo 'error while uploading image';
            }

            // Uploading image into Server
            
            if ($uploadimgOK == 1) {
                move_uploaded_file($_FILES['files']['tmp_name'][$key], $targetFilePath);
                $uploadsuccess = 1;
            }else{
                echo 'error while uploading project';
                $uploadsuccess=0;
            }
        }
        
        // After project is sucessfully uploaded, it redirects to the next page

        if ($uploadsuccess == 1) {
            header('Location: testesucesso.html');
            exit();
        }
    }
}

HTML

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Project Upload</title>
</head>
<body>
    <h2>Upload Projects</h2>
    <form action="inserir_db.php" method="POST" enctype="multipart/form-data">
        <div>
            <label for="project1Name">Project Name:</label>
            <input type="text" id="nome" name="nome">
            <br>
            <label for="project1Description">Turma:</label>
            <textarea id="turma" name="turma" rows="4" cols="50"></textarea>
            <br>
            <label for="project1Image1">Image 1:</label>
            <input type="file" id="img" name="files[]" accept="image/*" multiple>
            <br>
            <br><br>
        </div>
        <input type="submit" value="UPLOAD">
    </form>
</body>
<script type="javascript">
    
</script>
</html>

New contributor

Aozakiii is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật