/    Sign up×
Community /Pin to ProfileBookmark

how should it be stored

I have a membership form that users must fill in. It allows the user to upload a photo of them selves also. However, when they submit the form, all of the information goes into the database and the image uploads into a certain directory, however the image may have uploaded but the database does not know anything about the image. I have a field in the database called file (which is for the photo). How do i link the photo to this field so that when the site tries to call the users information back, it can call the photo aswell.

to post a comment
PHP

13 Comments(s)

Copy linkTweet thisAlerts:
@MatMelJan 19.2007 — Why don't you only store the filename (and if necessaray directory) in the database and print this into a normal <img> tag?

e.g. the photo is uploaded to "images/user1234.jpg", you store this path in the db and output it like that:
[code=php]echo" <img src='" . $row['file'] . "'>"; [/code]
Copy linkTweet thisAlerts:
@oo7mlauthorJan 19.2007 — Yeah i understand that, that is what i am hoping to do, but how to i actually put the filename (and if necessary directory) into the database once the form is submitted. (how do i actually get the text into the field in the table)

And say a user uploads an image that is called something that may seem obscure, is there a way that every image that is uploaded is renamed and called 1,2,3... and so on (incremented)
Copy linkTweet thisAlerts:
@netbuddyJan 19.2007 — If you take a look at the [b]Sticky[/b] posts at the top of this forum, you will find an uploader routine and multiple uploader routine.
Copy linkTweet thisAlerts:
@oo7mlauthorJan 19.2007 — I have looked at the sticky, there is no indication in that to show how to write the image name into the database. Anyone else know how to do it
Copy linkTweet thisAlerts:
@MatMelJan 19.2007 — Well, then you will have to deal with mySQL before you start trying to code the upload script.

Google and this forum will help you ( I only know German Tutorials so I cannot advise you one ...).

For a start try
[code=php]
mysql_query("INSERT INTO table SET file='blabla'");
[/code]
Copy linkTweet thisAlerts:
@bokehJan 19.2007 — [CODE]INSERT INTO table SET file='blabla'[/CODE][/QUOTE]That query looks a bit suspect to me. [CODE]INSERT INTO [I]tablename[/I] ([I]filename[/I]) VALUES ('blabla')[/CODE]
Copy linkTweet thisAlerts:
@oo7mlauthorJan 19.2007 — Is there no way that when the user submits their form that the image path is entered into the database along with all their other info aswell. I have used the STICKY for uploading images but i can't seem to find where he has carried out this part
Copy linkTweet thisAlerts:
@bokehJan 19.2007 — The sticky is just a start. Why don't you post some code so you can be provided with some relevant advice?
Copy linkTweet thisAlerts:
@NightShift58Jan 19.2007 — I have a field in the database called [B]file[/B] (which is for the photo). [/QUOTE]Hence:[code=php]INSERT INTO table SET file='blabla'[/code]would be okay... if there were only one field in the table. You'll want to perform the INSERT with the rest of the fields that belong to that record.
Copy linkTweet thisAlerts:
@bokehJan 19.2007 — [code=php]INSERT INTO table SET file='blabla'[/code][/QUOTE]Looks like an UPDATE query to me but a look at the manual seems to indicate it is valid syntax.
Copy linkTweet thisAlerts:
@NightShift58Jan 19.2007 — In line with my other coding idiosyncrasies, it's the syntax I prefer...

But in my post, I was only referring to the incorrect fieldname ("file" insteaf of "filename").
Copy linkTweet thisAlerts:
@MatMelJan 20.2007 — That query looks a bit suspect to me. [CODE]INSERT INTO [I]tablename[/I] ([I]filename[/I]) VALUES ('blabla')[/CODE][/QUOTE]
I like this notation more than yours because you have the colname directly beside the value. And it has the same usability than the other statment.

You can use it for multiple cols too:

[code=php]
INSERT INTO table SET col1='wurst', col2='essen', col3='ist', col4='gut'
[/code]
Copy linkTweet thisAlerts:
@NightShift58Jan 21.2007 — [code=php]INSERT INTO table SET col1='wurst', col2='essen', col3='ist', col4='gut'[/code][/QUOTE]Ob Wurst essen gut ist, darüber lässt sich streiten...?
×

Success!

Help @oo7ml spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...