By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,985 Members | 1,712 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,985 IT Pros & Developers. It's quick & easy.

displaying an image in php from an xampp database

P: 5
Ive written code in php and have managed to connect to the database and show all the information from it except the image (BLOB) file. This is the code so far.....

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. $con = mysql_connect("localhost","root","");
  4. if (!$con)
  5. {
  6. die ('Could Not Connect:' . mysql_error());
  7. }
  8.  
  9. mysql_select_db("membership",$con);
  10.  
  11. $result = mysql_query ("SELECT * FROM members");
  12.  
  13. echo "<table border='1'>
  14. <tr>
  15. <th> headers </th>
  16. <th> headers1 </th>
  17. <th> headers2 </th>
  18. <th> headers3 </th>
  19. <th> headers4 </th>
  20. </tr>";
  21.  
  22. while ($row = mysql_fetch_array($result))
  23. {
  24. echo "<tr>";
  25. echo "<td>" . $row['photo'] . "</td>";
  26. echo "<td>" . <img src=\"members.php?file={$row["photo"]}\">" . "</td>";
  27. echo "<td>" . $row['headers'] . "</td>";
  28. echo "<td>" . $row['headers1'] . "</td>";
  29. echo "<td>" . $row['headers2'] . "</td>";
  30. echo "<td>" . $row['headers3'] . "</td>";
  31. echo "<td>" . $row['headers4'] . "</td>";
  32. echo "</tr>";
  33. }
  34. echo "</table>";
  35.  
  36. mysql_close($con);
  37.  
  38. ?>
How do I fix this please??
Mar 22 '12 #1
Share this Question
Share on Google+
10 Replies


Dormilich
Expert Mod 5K+
P: 8,639
where is the code to display the image itself?
Mar 22 '12 #2

P: 5
do i need that if the image is already stored in a database?
I'm new to this and I don't quite understand how this works!!

If all the information from the table displays on the page shouldn't the image do that to?
It only displays like an icon of where the image would be....
Mar 23 '12 #3

Dormilich
Expert Mod 5K+
P: 8,639
do i need that if the image is already stored in a database?
can a browser read a database directly?


If all the information from the table displays on the page shouldn't the image do that to?
which brings us to the question: how does HTML display an image?


It only displays like an icon of where the image would be....
answer 0.5: not like it displays text, obviously …
Mar 23 '12 #4

P: 5
okay, well how can I fix it?
Mar 23 '12 #5

Dormilich
Expert Mod 5K+
P: 8,639
fix what?
Mar 24 '12 #6

P: 5
it not displaying an image...... like am i missing code or have i done something wrong?
Mar 24 '12 #7

Dormilich
Expert Mod 5K+
P: 8,639
to start from the beginning, how do you (try to) display the image?
Mar 24 '12 #8

P: 5
i put an <img src> tag in a row
Mar 24 '12 #9

Expert Mod 100+
P: 2,327
The data in $row['photo'] is a blob, it isn't an image, you can't output it. You have to take that data and then either create a script that will output it as an image, or you can write it to a file. It is data that is most likely binary(images).

Read up on how to create image files with blob data in database.
Mar 24 '12 #10

helimeef
P: 77
Well, another potential problem would be that you don't have an opening quote before your <img> tag:

Expand|Select|Wrap|Line Numbers
  1. echo "<td>" . <img src=\"members.php?file={$row["photo"]}\">" . "</td>";

Should read:

Expand|Select|Wrap|Line Numbers
  1. echo "<td>" . "<img src=\"members.php?file={$row["photo"]}\">" . "</td>";
Mar 25 '12 #11

Post your reply

Sign in to post your reply or Sign up for a free account.