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>";
}
}