Display an image from a MySQL database using PHP

Nosmig

New to this but loving it. I have a database of URLs of pictures of cats that I want to display in a webpage. I wrote some php to do this but all I'm seeing it the URL of the image and not the image itself. Here is my full code:

<html>
<body>
<h1>Katz!!</h1>

<!--Connect to Database-->
<?php
$db_host = "localhost";
$db_username = "Alex";
$db_pass = "";
$db_name = "cats";

@mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mySQL");
@mysql_select_db("$db_name") or die ("No database");

$sql="SELECT * FROM cats_test";
$records = mysql_query($sql);
?>

<!--Populate table from database-->
<table  border="2" cellpadding="1" cellspacing="1">
<tr>
    <th>cat table</th>
</tr>
<?php
while($cats_test=mysql_fetch_assoc($records)) {
    echo "<tr>";
    echo "<td>".$cats_test['image']."</td>";
    echo "</tr>";
}
?>
</table>
</body>
</html>

As you can see, the database name is "cats" with a table called "cats_test" that holds all of the images in a column called "image" you can find a screenshot of that here

You can also see the URLs being displayed instead of images here

I've probably done something really stupid, so would appreciate any help you guys might have!!

Raphaël Vigée

Replace your :

echo "<td>".$cats_test['image']."</td>";

With :

echo "<td><img src='".$cats_test['image']."' ></td>";

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Display an image from a MySQL database using PHP

From Dev

how to display image from database using php and mysql in a html page

From Dev

PHP MySQL display image from database

From Dev

How to retrieve image file paths from mysql database and display the images using php

From Dev

How to retrieve image file paths from mysql database and display the images using php

From Dev

Upload image in MYSQL database & display it using PHP with Swift

From Dev

Display Image on website from mysql database via php

From Dev

Not being able to display Image from MySQL Database in PHP

From Dev

image display from database in php

From Dev

How to display image from mysql database using spring mvc

From Dev

How to display a link from the MySql database in html using jquery or php

From Dev

Format using MYSQL Date Retrieved from Database and Display in PHP file

From Dev

How to display images from database mysql using php?

From Dev

How to display Decimal and Date Arrays from MySQL database using php

From Dev

Display blob image from database in php

From Dev

How to display an image from a database using ajax

From Dev

PHP display image BLOB from MySQL

From Dev

How to I display image from mysql PHP

From Dev

how to display image from mysql in php

From Dev

Display data from mysql database using a table

From Dev

upload image from submit form to mysql database and display image in div?

From Dev

upload image from submit form to mysql database and display image in div?

From Dev

PHP Upload image to mysql database using PDO?

From Dev

Display info from a database on a webpage using php

From Dev

How to get the an image from mysql database in php

From Dev

php ,mysql image is not displaying from database

From Dev

How to get the an image from mysql database in php

From Dev

How to display image from database instead of image path using jQuery

From Dev

How to display image from database instead of image path using jQuery

Related Related

  1. 1

    Display an image from a MySQL database using PHP

  2. 2

    how to display image from database using php and mysql in a html page

  3. 3

    PHP MySQL display image from database

  4. 4

    How to retrieve image file paths from mysql database and display the images using php

  5. 5

    How to retrieve image file paths from mysql database and display the images using php

  6. 6

    Upload image in MYSQL database & display it using PHP with Swift

  7. 7

    Display Image on website from mysql database via php

  8. 8

    Not being able to display Image from MySQL Database in PHP

  9. 9

    image display from database in php

  10. 10

    How to display image from mysql database using spring mvc

  11. 11

    How to display a link from the MySql database in html using jquery or php

  12. 12

    Format using MYSQL Date Retrieved from Database and Display in PHP file

  13. 13

    How to display images from database mysql using php?

  14. 14

    How to display Decimal and Date Arrays from MySQL database using php

  15. 15

    Display blob image from database in php

  16. 16

    How to display an image from a database using ajax

  17. 17

    PHP display image BLOB from MySQL

  18. 18

    How to I display image from mysql PHP

  19. 19

    how to display image from mysql in php

  20. 20

    Display data from mysql database using a table

  21. 21

    upload image from submit form to mysql database and display image in div?

  22. 22

    upload image from submit form to mysql database and display image in div?

  23. 23

    PHP Upload image to mysql database using PDO?

  24. 24

    Display info from a database on a webpage using php

  25. 25

    How to get the an image from mysql database in php

  26. 26

    php ,mysql image is not displaying from database

  27. 27

    How to get the an image from mysql database in php

  28. 28

    How to display image from database instead of image path using jQuery

  29. 29

    How to display image from database instead of image path using jQuery

HotTag

Archive