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

How to retrieve image from database

P: 3
dear Sir/madam

I am getting a problem while displaying a image from database

Database : MSSQL2000

I have a table named “Image” having following fields as

Expand|Select|Wrap|Line Numbers
  1. ImageId    int
  2. Image        Image
  3. FileType    image/jpeg
I am using two PHP pages

First PHP page (list.php) as

[PHP]<?php
$errmsg = "";
if (! @mssql_connect("10.147.16.167","sa",""))
{
$errmsg = "Cannot connect to database";
}
@mssql_select_db("epass");

$strSQL = "select * from Image";
$rsPix = mssql_query($strSQL);
$numRows = mssql_num_rows($rsPix);

$i = 0;

while($i < $numRows){
?>

<img src="pix.php?pixID=<?php echo mssql_result($rsPix,$i,"pixID"); ?>" width="100" height="100"/>
<?php
$i++;
}
?>
[/PHP]

Second PHP page as (pix.php)

[PHP]<?php
$errmsg = "";
if (! @mssql_connect("10.147.16.167","sa",""))
{
$errmsg = "Cannot connect to database";
}
@mssql_select_db("epass");

if (IsSet($_GET['pixID'])){
//$gotten = @mssql_query("select Image from Image");
$gotten = @mssql_query("select Image from Image where ImageId = ".$_GET['pixID']);

header("Content-type: image/jpeg");
while ($row = mssql_fetch_array($gotten))
{
echo "**************";
print $row['Image'];

}
mssql_free_result($gotten);
}
?>[/PHP]

Here I am running the list.php where an image box appears with cross button (no image is displaying in the image box)

It is kindly requested to see the problem. I will be very grateful to you guys

thanking you in anticipation
Brijesh
Oct 16 '08 #1
Share this Question
Share on Google+
3 Replies


Atli
Expert 5K+
P: 5,058
Brijesh.

Please use [code] tags when posting your code examples. (See How to ask a question)

[code=php] ...PHP code goes here... [/code]

Thank you.
Oct 16 '08 #2

Atli
Expert 5K+
P: 5,058
On line 16 in your second file, why do you echo a bunch of * chars before the contents of the image?
That would surely corrupt the image.
Oct 16 '08 #3

100+
P: 190
FYI

While u want to display the image, do not ecoh any word in that area.
Oct 16 '08 #4

Post your reply

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