0

I'm currently working on a way to submit a image using a form to a table in one of my databases. I got everything else done except for the image part, I looked at some tutorials, but their rather confusing. I was thinking maybe I could get some help here?

HTML:

        <form action="" method="post" enctype="multipart/form-data">
            <h1>Service Name: </h1>
            <select name="serviceNamesForm">
                <?php

                    require_once 'includes/dbh-inc.php';

                    $sql = "SELECT serviceName FROM addService;";   
                    $result = $conn-> query($sql);
                    while ($row = $result-> fetch_assoc()) {
                            $service_name = $row['serviceName'];
                            echo "<option value='$service_name'>$service_name</option>";
                        }
                    
                    
                ?>
                <br></br>
                
                <input type="text" name="product" placeholder="Product Name...">
                
                <br></br>
                
                <input type="file" name="productImage">
                
                <br></br>
                
                <input type="submit" value="Submit">
                
                
                
            </select>
        </form>
xSmiiB
  • 51
  • 6
  • 1
    To be honest, storing files in a database is an inherently bad idea. By including files you make your database much larger which can then affect performance and support services like backups. I would store the images in the file system or a cloud service and then only store a path to the image in your DB. – Dazz Knowles Jul 26 '21 at 16:27
  • Alright, I'll take that into consideration thank you. – xSmiiB Jul 26 '21 at 16:32
  • you can store the name of the file and the path in your database, but store the file itself in the file system. –  Jul 27 '21 at 01:06
  • Although it's not great practice storing files within the database, one way to do it is to convert the file into base64. [PHP base64 encode a pdf file](https://stackoverflow.com/questions/34182379/php-base64-encode-a-pdf-file/34182554) – Rylee Jul 27 '21 at 04:09

0 Answers0