I have this code that is supposed to fetch an image from my server and display it on my html. My images are encrypted in md5 and when uploading them to the server there is no field in my table that stores the names of the images. I am therefore calling the image using the primary key in the table to get the image.
Here is my code:
<?php
// connection string constants
define('DSN', 'mysql:dbname=mydbname;host=localhost');
define('USER', 'myuser2015');
define('PASSWORD', 'mypwd2015');
// pdo instance creation
$pdo = new PDO(DSN, USER, PASSWORD);
// query preparation
$stmt = $pdo->query("
SELECT title, introtext, id, created, created_by, catid
FROM mytbl_items LIMIT 4
");
// fetching results
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
// if this returns 0 then it means no records are present
echo count($result) . "
";
// the loop should print valid table
foreach ($result as $index => $row) {
if ($index == 0) echo '<div>';
echo <<<HTM
<img style='width:100%; height:200px;' echo "../media/k2/items/cache/".md5("Image".{$row['id']})."_XL.jpg";
<span class="post-date">{$row['created']}</span>
<h2 class="blog-post-title">{$row['title']}</h2>
<p>
{$row['introtext']}
</p>
<p>
<a href='read.php?id={$row['id']}'><input type="button" value="Read More" /></a>
</p></br>
<div class="blog-meta">
<img src="img/icons/logo.png" alt="Avatar" />
<h4 class="blog-meta-author">{$row['created_by']}</h4>
<span>Category: {$row['catid']}</span>
</div>
HTM;
if ($index == (count($result)-1))echo '</div>';
}
What mistake am I making with the code that is supposed to fetch the image? This is the line
img style='width:100%; height:200px;' echo "../media/k2/items/cache/".md5("Image".{$row['id']})."_XL.jpg";
Remove second echo
from your here/nowdoc. You already started echo
ing in
echo <<<HTM