Jump to content

DISPLAYING an image from MySQL database into HTML table.


DarnStuckAgain

Recommended Posts

Not really sure how to get the images I have stored in MySQL into a html form. I can call-up the text fields from the database but it cannot seem to find the index for the images.

 

Here is my code:-

 

<?php

session_start();

mysql_connect("localhost","root","abc") or die ("Error! Cannot connect to database");

mysql_select_db("theimageworks") or die ("Cannot find database");

$query = "SELECT * FROM jobs";

$result = mysql_query($query) or die (mysql_error());

?>

 

 

<?php

//display data in html table

echo "<table>";

echo "<tr><td>Username</td><td align='center'>Message</td><td>Product Image</td></tr>";

 

while($row = mysql_fetch_array($result)) {

echo "</td><td>";

echo $row['username'];

echo "</td><td>";

echo $row['message'];

echo "</td></tr>";

echo $row['image'];

    }

echo "</table>";

?>

 

The error message I get is "Notice: Undefined index: image in....."

 

Thanks in advance!

Yes I am storing images in a database for learning purposes (I know it's not recommended).

 

You were right I wrote the wrong table name sorry about that -.-

 

The code is changed to this now :-

 

echo "<img src='".$row['jobimage']."'>";

 

but I am getting a huge screen filled with random symbols like "HªG<Œ€:”®ì[vW¬¬e•™L¡K»Ô⩾y$M¹Q›owuŒ›Ir"

 

 

If you'd rather not use another script for images, you could embed them into your page with the data URI scheme. There's obvious downsides to that though.

 

echo "<img src='data:image/jpeg;base64,".base64_encode($row['jobimage'])."'>";

 

EDIT: just read that other post, that's one downside.

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.