saving and viewing a image from mysql

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
swissbeets
Forum Newbie
Posts: 20
Joined: Thu Jun 26, 2008 7:56 pm

saving and viewing a image from mysql

Post by swissbeets »

i am new relatively new to php and am at a point now where i want to be able to store image locations on my database. i have already made a table for it but now i am at the back and front end capabilities. i need help knowing

1# how to be able to upload the file name and have it store to my database
(i know it can just be typed in but what is the best way to have this done so there are less errors)
2# how to have the pictures be shown when called upon with the rest of the information

any help would be greatly appreciated thank you.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: saving and viewing a image from mysql

Post by califdon »

swissbeets wrote:i am new relatively new to php and am at a point now where i want to be able to store image locations on my database. i have already made a table for it but now i am at the back and front end capabilities. i need help knowing

1# how to be able to upload the file name and have it store to my database
(i know it can just be typed in but what is the best way to have this done so there are less errors)
2# how to have the pictures be shown when called upon with the rest of the information

any help would be greatly appreciated thank you.
#1 - there are lots of articles on uploading a single file or multiple files. Just search on php uploading multiple, for instance.

#2 - exactly the same way you would in plain html, within an <IMG ... /> tag. I presume you've echo'ed html table elements, like <tr><td> ... etc.? Just echo an image tag instead, with the $variable from the query as the SRC= parameter. Just remember to enclose the image name in quotes and if the images are in a separate directory, include the path. Sort of like:

Code: Select all

...
   echo "<img src='$filename' alt='The Grand Canyon' />";
...
or:

Code: Select all

$imgpath="images/";
...
   echo "<img src='".$imgpath.$filename."' alt='The Grand Canyon' />";
...
Post Reply