Page 1 of 1

Images isn't showing

Posted: Fri Jul 11, 2014 7:03 am
by fahim
Hi,

I'm quite new to PHP. As a part of my learning process, I'm trying to show a list of images in a page, but unfortunately the images aren't showing !!! :banghead:

I've saved my variables in a seperate file, in there I've saved the upload path, like below :

Code: Select all

define('MM_UPLOADPATH', 'images/');
After that, I've wrote the code and used that upload path by "require_once". The code is here :

Code: Select all

while ($row = mysqli_fetch_array($data)) {
    if (is_file(MM_UPLOADPATH . $row['picture']) && filesize(MM_UPLOADPATH . $row['picture']) > 0) {
      echo '<tr><td><img src="' . MM_UPLOADPATH . $row['picture'] . '" alt="' . $row['first_name'] . '" /></td>';
    }
    else {
      echo '<tr><td><img src="' . MM_UPLOADPATH . 'nopic.jpg' . '" alt="' . $row['first_name'] . '" /></td>';
    }
    echo '<td>' . $row['first_name'] . '</td></tr>';
  }
After this I've put the images in the "images" folder, located in the same folder with the "index.php".

It seems everything is okay to me, but unfortunately the images are missing when I'm accessing the page via a browser (please check the attached screenshot)

I'd be really grateful if anyone could help me to solve this issue.

Thanks in advance.

Re: Images isn't showing

Posted: Fri Jul 11, 2014 7:12 am
by Celauran
Have you checked the image path in the rendered source?

Re: Images isn't showing

Posted: Fri Jul 11, 2014 10:11 pm
by fahim
Really thanks for your reply, but it's not clear to me that, what you are trying to mean by "rendered source"? Would you please clarify it?

Re: Images isn't showing

Posted: Sat Jul 12, 2014 6:54 am
by Celauran
Load the page in your browser, view source, check the image path.

Re: Images isn't showing

Posted: Sun Jul 13, 2014 9:09 am
by fahim
Thanks for the clarification. In the browser, when I'm viewing the source, I'm getting any image path (maybe because I'm using "require_once" and saved that path in a different file). Whatever the source is here. Believe that you'll understand the problem from this :

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Mismatch - Where opposites attract!</title>
  <link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
  <h3>Mismatch - Where opposites attract!</h3>

&#10084; <a href="viewprofile.php">View Profile</a><br />&#10084; <a href="editprofile.php">Edit Profile</a><br /><h4>Latest members:</h4><table></table>
</body> 
</html>
Thanks in advance.

Re: Images isn't showing

Posted: Sun Jul 13, 2014 12:27 pm
by Christopher
There are no images -- so either there is some error in the MySQL connection or query, or there are no rows returned by the query.

Re: Images isn't showing

Posted: Wed Jul 16, 2014 6:43 am
by fahim
Thanks everyone for your help. My problem is solved. Marking this post as SOLVED.