Hi I'm new to PHP and MySQL. Please help me with this... Thanks alot! I'm having problems with displaying images whose binary data are stored in database. I'm using <img src="simple_picture.php"> to produce the image. If you have seen my code, I'm trying to pass $pictureId to simple_picture.php so that the query can be carried out. There are no forms so I can't use HTTP_POST_VARS.
I would like to display a table like this:
Picture Filename
imageA ABC.gif
imageB XYZ.gif
imageC qwert.jpeg
My limitations:
1) register_global=off.
2) actual image binary data must be stored in database.
So far, I've written this:
//get the pictures this user has saved
if (!($conn = db_connect()))
return false;
$result = mysql_query( "select pictureId, filename
from pictures
where username = '$valid_user'");
if (!$result)
echo "Error retrieving data.";
//create an array of the result
$picture_array = array();
for ($count = 0; $row = mysql_fetch_row ($result); ++$count)
{
$picture_array[$count] = $row;
}
//display the table of pictures
?>
<br><br>
<table border="10" cellpadding=2 cellspacing=0>
<tr>
<td>Picture</td>
<td>File name</td>
</tr>
<?php
if (is_array($picture_array) && count($picture_array)>0)
{
foreach ($picture_array as $picture)
{
echo "<tr><td>";
session_register("pictureId");
$pictureId = $picture[0];
?><img src = "simple_picture.php"><?php
echo "</td>";
echo "<td>".$picture[1]."</td>";
echo "</tr>";
}
}
else
{
echo '</table>';
echo "<tr><td>No pictures on record</td></tr>";
}
?>
</table>
AND IN SIMPLE_PICTURE.PHP:
<?php
require_once("all_functions.php");
session_start();
if (!($conn = db_connect()))
return false;
$valid_user = $HTTP_SESSION_VARS["valid_user"];
$pictureId = $HTTP_SESSION_VARS["pictureId"];
if(!$pictureId)
echo $pictureId;
$result = mysql_query( "select photoBinary, filetype
from pictures
where username = '".$valid_user."' and pictureId = '".$pi."'")
or die("Couldn't get image");
$photoBinary = @mysql_result($result,0,"photoBinary");
$filetype = @mysql_result($result,0,"filetype");
mysql_free_result($result);
Header("Content-type: $filetype");
echo "$photoBinary";
?>
THE ERROR IS:
Always a red X appear in the Picture field.