Problem displaying my images & info


i’ve built an application whereby i would upload an image onto my server allong with its info stored on my db which works fine. I am now trying to display my images and info together in my homepage.html.php file but when try to do this nothing is displayed.

What i don’t understand is in the book, ‘Build Your Own Database Driven Website using PHP & MYSQL 4th ed’ there are many examples in this book e.g chapter 7p223/4 which uses a while loop to get the results from the db and and uses the include ‘jokes.html.php’ code to display their results, it seems to work there but when i do it myself nothing appears, why? What am i missing?

include $_SERVER['DOCUMENT_ROOT'] . '/includes/';
       $result = mysqli_query($link, "SELECT * FROM image_detail");
   if(!$result )
        $error = 'Error fetching image data from database';
        include 'error.html.php';
    while ($row = mysqli_fetch_array($result))
        $images[] = array('Filename' => $row['Filename'], 'Description' => $row['Description'], 'Category' => $row['Category']);

    include 'homepage.html.php';

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="" xml:lang="en" lang="en">
		<title> Image Upload Success</title>
		<meta http-equiv="content-type"
				content="text/html; charset=utf-8"/>
			<?php if( isset($images) ): ?>
			<?php foreach ($images as $image): ?>
			<tr valign="top">
				<td><? php echo '<img src="./images/'.$image['photo'].'" >';  ?> </td>
			<?php echo "<b>Description:</b> ".$image['Description'] . " <br>"; ?>
			<?php endforeach; ?>
			<?php endif ;?

Please help thanks

Forgive me, I’ve got the concept behind include pretty wrong. I’ve just realised how it works - it seems to me that it includes them as if there is an invisible ?> added right before the inclusion, and an <?php right after it.

Not true. Included files are not evaluated as PHP code (unlike using eval()), so the above method would work fine.


Seperating the html like that is fine. As you said, it’s keeping the application logic and display logic seperate.

As for why you get a blank page; if you look at the html code you posted, you’ve missed the ending ‘>’ from the last ‘endif’ statement, causing a parse error.

To help debug this sort of stuff, setting the level or error reporting would be useful, i.e:

error_reporting(E_ALL & ~E_NOTICE);

and i als don’t see my images and text

messy reayll? But why does the book have it this way? having all the logic in the index.php file and doing all the display stuff in the .html.php file because obviously i’m trying to use the same technique onto my project. To me it seems reasonable

When you include that HTML in your PHP script it’s just as if you’d copy-pasted it straight into the PHP script. It will therefore cause all sorts of problems because PHP doesn’t understand HTML and you’re adding inside <?php ?> tags. If you put a ?> tag right at the beginning of the HTML, then it should work. But it’s a rather messy way of doing this. You might as well just have it all in the same .php file.

I added a ?> at the beginning of my html i.e ?><html xmlns="http://www.w3… which i assume is what you are referring to right? if so, after adding that, all i see is the ?> on my web browser not my images unless i missunderstood you.