I am trying to select all data from my database, everything works except image, it is shown as a broken image. In my root folder I have img folder with images, and code I use for it when adding it to html is img/someimage.png
Creating table:
CREATE TABLE IF NOT EXISTS `post` (
`title` text COLLATE utf8_unicode_ci NOT NULL,
`date` date NOT NULL,
`text` longtext COLLATE utf8_unicode_ci NOT NULL,
`imgpath` varchar(50) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `post` (`title`, `date`, `text`, `imgpath`) VALUES
('Some text.', 'img/winning-1.png');
Connecting to database (i have included connection.php)
<?php
$sql="SELECT * FROM post";
if (!$q=$mysqli->query($sql)){
echo "<p>Error</p>" . mysql_query();
exit();
}
if ($q->num_rows==0){
echo "<p>Empty!</p>";
} else {
?>
<table>
<?php
while ($red=$q->fetch_object()){
?>
<tr>
<td><?php echo $red->title; ?></td>
<td><?php echo $red->date; ?></td>
<td><?php echo $red->text; ?></td>
</tr>
<img src="<?php echo $red->imgpath; ?>" />
<?php
}
?>
</table>
<?php
}
?>