954,561 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to retrieve images from database

<?php
$conn = mysql_connect("localhost", "root", "general");
mysql_select_db("cms");
$result = mysql_query("SELECT * FROM Category");
echo "";

//$cimage =
while($take = mysql_fetch_array($result))
{
echo"";
echo "";
print $take['cat_name']."
";
echo "";
print $take['cat_desc']."
";
echo "";
echo "";
echo $take['cat_image']."
";
echo "";
echo "";
}
echo "";
echo "";
echo "


";
mysql_close($conn);
?>

this is my code to get the images from the database...
i have uploaded the images...
but..when i tried to view it only the image name appears..the image doesnt appear...
The image name in the mysql is called cat_image

tryphy
Junior Poster in Training
79 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

My suggestion is to put the path to the image in the database. eg http://www.[name].com/images/cat_image.jpg
and then echo it inside an image tag.

Venom Rush
Posting Whiz
353 posts since Oct 2007
Reputation Points: 31
Solved Threads: 2
 

echo $take['cat_image']. put it inside the image...

ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

thanks...
will try and let know how it wrks..

tryphy
Junior Poster in Training
79 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

i tried through it ..but i get an error...
Parse error: syntax error, unexpected '<' in ....

tryphy
Junior Poster in Training
79 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

echo ".$take[";

put necessary quotes to display image.

ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

oops!I also made the wrong concatenation. try this one if the latter produces the same error.

echo "".$take[";

ryan_vietnow
Posting Pro
578 posts since Aug 2007
Reputation Points: 28
Solved Threads: 71
 

The way I was thinking was to upload the image to the ftp and then INSERT the path to where the image is inside the database.

Then essentially you'd retrieve the path of the image from the database and insert it inside an img tag.

Venom Rush
Posting Whiz
353 posts since Oct 2007
Reputation Points: 31
Solved Threads: 2
 

The way I was thinking was to upload the image to the ftp and then INSERT the path to where the image is inside the database.

Then essentially you'd retrieve the path of the image from the database and insert it inside an img tag.


Hi....
venom rush....
Thanks for the suggestion...i will try that also...

But the echo one works...
i can see only the image tag...that is the box, but not the image....
when i upload the image...i upload into a folder ..
and also to mysql..

<?php
$query = "INSERT INTO category(cat_name, cat_desc, cat_image)" .
"VALUES('$cname', '$cdesc','$cimage')";
mysql_query($query,$link)
or die("Couldn't add data to add to \"Category\" table:
".mysql_error($link));
mysql_close($link);
?>

This is how I insert into mysql..
but still i cudnt able to see the image...
Did i made any wrong...?

tryphy
Junior Poster in Training
79 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

i have a problem with images on my server where the extension will change to uppercase when uploaded. some servers will not display the image if the extension in the database and the one in the folder are not the same.

also did you add the folder to the path. (/folder/image.jpg)

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

i think the reason is file extensions...

fatihpiristine
Posting Whiz in Training
283 posts since Sep 2007
Reputation Points: 6
Solved Threads: 19
 

i have a problem with images on my server where the extension will change to uppercase when uploaded. some servers will not display the image if the extension in the database and the one in the folder are not the same.

also did you add the folder to the path. (/folder/image.jpg)


Is the column type where u store the path to the image VARCHAR?

Venom Rush
Posting Whiz
353 posts since Oct 2007
Reputation Points: 31
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You