Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
displaying images from a database
Old 02-14-2009, 06:08 PM displaying images from a database
Average Talker

Posts: 21
Name: Hal
Trades: 0
I have a mysql database and want to have one column display images.
I created a folder called 'images' for my jpg's.

Ran this code:
[code ]
update gpstable set pic = '<img src="/images/maestro4210.jpg" alt="Maestro 4210" />' WHERE id = '3';
[/code ]

Now the table displays a small broken-link picture.

Is there something wrong with my sql statement?
hoco is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 02-14-2009, 06:13 PM Re: displaying images from a database
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Try:
Code:
UPDATE `gpstable` SET `pic` = '<img src="/images/maestro4210.jpg" alt="Maestro 4210" />' WHERE `id` =3 LIMIT 1
SQL can be a bit iffy about capitalisation (it seems to prefer it)
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-14-2009, 06:24 PM Re: displaying images from a database
Average Talker

Posts: 21
Name: Hal
Trades: 0
Tried it - same result.
Curious - What is LIMIT 1?
hoco is offline
Reply With Quote
View Public Profile
 
Old 02-14-2009, 07:08 PM Re: displaying images from a database
NullPointer's Avatar
Will Code for Food

Posts: 2,784
Name: Matt
Location: Irvine, CA
Trades: 0
Try it without the relative path (ie http://mysite.com/images/image1.jpg).

Rather than storing the path to an image, you can also store the image itself using the blob data type.
http://www.phpriot.com/articles/images-in-mysql
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-14-2009, 07:36 PM Re: displaying images from a database
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Escape the inputs from quotes etc. first, for example with the mysql_real_escape() function, before you put them in an SQL query.

Courious too :P - And why are you storing a complete html tag? Why not just save the path and put it in an <img> tag your self when you need it? As in

UPDATE gpstable SET pic='/images/picture.jpg' WHERE id='3' LIMIT 1

The 'LIMIT 1' clause makes sure only 1 row is affected. So in case something goes bad, for exmaple if some jackass manages to make an SQL injection attack or similar and tries to screw thing up for you, it will still only affect one row instead of, lets say the whole table.
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 02-14-2009, 07:57 PM Re: displaying images from a database
Average Talker

Posts: 21
Name: Hal
Trades: 0
Tried:
UPDATE gpstable SET pic='/images/picture.jpg' WHERE id='3' LIMIT 1

Displays:
/images/maestro4210.jpg
instead of the actual picture.
hoco is offline
Reply With Quote
View Public Profile
 
Old 02-14-2009, 08:44 PM Re: displaying images from a database
Average Talker

Posts: 21
Name: Hal
Trades: 0
Also tried the full path and found out that my database needs reconfiguring for more characters.
hoco is offline
Reply With Quote
View Public Profile
 
Old 02-15-2009, 05:44 AM Re: displaying images from a database
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
Of course it only displays the path :P
I meant for you to put the path in an <img> tag your self, like this
PHP Code:
echo '<img src="' $path '">'// Where $path is the 'pic' value from the database 
lizciz is online now
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Reply     « Reply to displaying images from a database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.94315 seconds with 12 queries