0

First off, I am VERY new to PHP coding. I've been more than a few days getting everything to work that is working and have been watching hours of video. Yet, for the life of me, I cannot get this to "completely" function.

When I click my upload button, the author, date_time group, and the comment work fine. They are posting to the database and posting to the "GET" section when I click upload. The thumbnail on the other hand just gives the broken path image. I'm sure it's something I'm not defining correctly, but I am completely lost. I have posted my comment box form source code, connection, and functions. My database is in commentsection/comments/image. The "image" column of the database type is set to BLOB.

Please help...

SOURCE CODE:

<?php
echo "<form method='POST' enctype='multipart/form-data 'action='".setComments($conn)."'>
    <input type='hidden' name='uid' value='Anonymous'>
    <input type='hidden' name='date' value='".date('Y-m-d H:i:s')."'>
    <label>Upload Image</label><br>
    <input type='file' name='image' id='image'><br>,<br>
    <textarea name='message'></textarea><br><br>
    <button type='submit' name='commentSubmit'>Upload</button>
</form>";


getComments($conn);     
?>

CONNECTION:

$conn = mysqli_connect('localhost','root','', 'commentsection');

if (!$conn) {
    die("Connection failed:".mysqli_connect_error());

}

FUNCTIONS:

<?php

function setComments($conn) {
if (isset($_POST['commentSubmit'])) {
    $uid = $_POST['uid'];
    $date = $_POST['date'];
    $message = $_POST['message'];
    $image = $_POST['image'];

    $sql = "INSERT INTO comments (uid, date, image, message) values ('$uid', '$date','$image', '$message')";
    $result = mysqli_query($conn, $sql);
}
}

function getComments($conn) {
    $sql = "SELECT * FROM comments ORDER BY date DESC LIMIT 10";
    $result = mysqli_query($conn, $sql);
    while ($row = mysqli_fetch_array($result)){
        echo "<div class='commentbox'><p>";
            echo $row['uid'];
            echo $row['date']."<br>";
                echo "<div class='thumbnail'>";
                    echo "<img src='".$row['image']."'>";
                echo "</div>";
            echo nl2br($row['message']);
        echo "<p></div>"."<br>";                    
    }

}
  • Possible duplicate of [How to retrieve images from MySQL database and display in an html tag](http://stackoverflow.com/questions/7793009/how-to-retrieve-images-from-mysql-database-and-display-in-an-html-tag) – Bagus Tesa Dec 15 '16 at 07:57
  • looked at that, but not sure what all applies to what I'm trying to do here. I'd like to be able to upload the image to the database and get it to save in a folder as an image then recall it in the get section. I tried using if (move_uploaded_file($_files['image']['tmp_name'}; but that didn't work to move the file to my folder – Don Collier Dec 15 '16 at 08:20
  • sorry, what about different approach..? [like this one](http://stackoverflow.com/questions/20556773/php-display-image-blob-from-mysql)..? although i am not sure when your `move_uploaded_file($_FILES['image']['tmp_name'])` fails, have you tried to `var_dump($_FILES)` ? anyway, [this q/a about naming might interest you](http://stackoverflow.com/questions/33273941/php-case-sensitivity) – Bagus Tesa Dec 15 '16 at 09:17

0 Answers0