For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > March 2007 > Re: [PHP-DB] echo









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] echo
Chris

2007-03-28, 3:58 am

elk dolk wrote:
> Hi all,
> I am new to web programming.
>
> I have code to add pictures to a MYSQL database. Now I can't seem to figure out how to get them back out ! so we can see them.
> The MySQL doesn't seem to be a problem (yet), also I'm trying to learn PHP.
>
> What I usually do is to load the images in a folder "img" and then the name of the pic (i.e. "myphoto.jpg") in the database, so i retrieve the name of the pic with:
>
> Code: <?php
> $connex = MySQL_connect(server,login,password);
> $sql_query = "select picname from photos where...";
> $result = MySQL_query($sql_query,$connex);
> $row = MySQL_fetch_array($result);
> ?>
>
> and then:
>
> Code: echo "<img src=".$row['photoFileName']." alt='photo'>";
>
> but I can't see the photo
> Any pointers or code samples will be greatly appreciated...


Are you storing the whole file in the database or just the path to the file?

If you're storing just the path, then your script is pointing to the
wrong directory and/or the file it's trying to reference doesn't exist
(or a permissions issue maybe).



If you're storing the whole file you need a new php script to pull it
back out.

Then in your html code you do:

echo '<img src="/path/to/display_image.php?image_id=' . $row['imageid']
.. '">';


That will hit 'display_image.php' and pull the image contents out of the
database.

See
http://www.phpriot.com/d/articles/d...ysql/page8.html
for an example.

--
Postgresql & php tutorials
http://www.designmagick.com/
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com