Jump to content

display image from uploaded directory (php mysql)


benidopogi

Recommended Posts

hi to all.Im currently displaying the images from my upload directory but the image does not display.please help thanks

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<form enctype="multipart/form-data">

<?php

include 'connect.php';

$dir = '/images/advisory';

$res = mysql_query("Select * from image_advisory

   INNER JOIN 

main_advisory

ON

image_advisory.advisory_id = main_advisory.id

  ");

 

echo"<table border='1px'>";

while($row=mysql_fetch_array($res))

   {

echo"<tr>";

 

echo"<td>"; echo $row['advisory']; echo "</td>";

 

echo"<td>";?><img src="<?php echo images/advisory/'.$row["ad_img"].'; ?>" height="100" width ="100" > <?php echo "</td>";//this is the error please help

 

 

echo"</tr>";

}

echo "</table>";

 

?>

</form>

</body>

</html>

post-173559-0-14044500-1416041526_thumb.png

It may be the relative directory path. You have defined $dir = '/images/advisory'; but in your img tags you use "images/advisory" without the preceding "/".

 

Also, why the <form> tags when you have no form inputs?

your img tag also is missing the opening ' and closing '

<?php echo images/advisory/'.$row["ad_img"].'; ?>

maybe try

<?php echo '/images/advisory/'.$row['ad_img'].''; ?>

View the output source and see what you are getting as the image path.

Might be a good place to start tracking the problem.

You can do the multiple echo with one

also eliminating the need to keep breaking in and out of php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form enctype="multipart/form-data">
<?php
include 'connect.php';
$dir = '/images/advisory';
$res = mysql_query("Select * from image_advisory
   INNER JOIN
main_advisory
ON
image_advisory.advisory_id = main_advisory.id
  ");

echo "<table border='1px'>";
while ($row = mysql_fetch_array($res)) {
    echo "<tr>";
   
    echo "<td>" . $row['advisory'] . "</td>";
   
    echo "<td><img src='" . $dir . "/" . $row['ad_img'] . "' height='100' width ='100' ></td>";
   
   
    echo "</tr>";
}
echo "</table>";

?>
</form>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.