0

I have an image posting to the database, and comes out as binary code in the "GET" section of the comments. Basically trying to post a thumbnail with the comment. How do I get the website section to recognize the binary coding of the image, in the database, as an image when it posts to the website?

Here are my 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";
    $result = mysqli_query($conn, $sql);
    while ($row = $result->fetch_assoc()){
        echo "<div class='commentbox'><p>";
            echo $row['uid'];
            echo $row['date']."<br>";
                echo "<div class='thumbnail'>";
                    echo $row['image'];
                echo "</div>";
            echo nl2br($row['message']);
        echo "<p></div>"."<br>";                    
    }

}
?>

1 Answers1

-1

Put it in src in your img HTML tag code. But keep in mind that databases are not working as well for storing images. You should store images in a folder and just keep their location in the database.

You may also switch to PDO instead of mysqli.

Adraqi
  • 51
  • 6
  • PDO is more recent and object query language, this will not solve this problem. Just a little suggestion. – Adraqi Dec 14 '16 at 14:52
  • I tried using if (move_uploaded_file($_file['image']['tmp_name']; but that didn't work. said that I had an undefined index image – Don Collier Dec 15 '16 at 07:58