Keeping it all together!

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
xterra
Forum Commoner
Posts: 69
Joined: Mon Mar 06, 2006 12:52 pm

Keeping it all together!

Post by xterra »

How is everyone. Thanks for having such a site.

I am new to PHP but am having a good time learning, with alot of success in my opinion. I created a succesfully mysql DB and I made it so I can use HTML forms to add records to the DB. That all works.

However, I want to be able to upload an image. I know there is an upload image script. However, if the user adds a record to the database, the image will get lost in my server with its random filename. How can I keep it together? In other words, is there anyway I can have the user upload the image first, then determine where that image is located, then add that location as an element in the record? That way the location of the image would be in the database as a column.

Any suggestions are appreciated.

Thanks,
Rob.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

Welcome to Devnetwork!

Assuming that the person is authenticated (logged in) and that he or she has a unique id number, you would simply put their unique id in the table with the record of where the file is stored at.

Have fun!

:)
xterra
Forum Commoner
Posts: 69
Joined: Mon Mar 06, 2006 12:52 pm

Post by xterra »

Thanks for the reply. I see what you mean, I was trying to avoid having memberships but I suppose that is the best alternative. For authentication, I can just have a seperate DB that has all the usernames a passwords? And then when the user submits their login info I just check it against whats in the DB?



But I'm a bit confused what I do once the user is authenticated. Say I have a table with the users, as you suggested:

USERNAME PASSWORD ID#



I don't understand how I incorporate that with the table I already have, that looks like this (called FileInfo)

FILE AUTHOR COMMENT COPYRIGHT


Sorry if that's confusing. But see it's almost as if I would need a table called FileInfo per user. But that wouldn't make sense though.


Thanks again,
Rob.
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

Post by neophyte »

You have to tie the data together, so in your tables it could be that author is the username from the other table. Although personally I'd ad a id field to your uploads table and just store the user's id number in there.
xterra
Forum Commoner
Posts: 69
Joined: Mon Mar 06, 2006 12:52 pm

Post by xterra »

Ok so I have two tables then:


Username or Personal ID | Password



User logs in. Is verified by that database. Maybe a welcome screen such as "Welcome " username.


The user decides to upload a picture. The database that will hold all the pictures will look like this:


File | Username or Personal ID | Comment | Copyright

someFile.jpg someUniqueUser This is a comment Copyright


And then each time the user logs on it will just use a SELECT query to display ONLY the pictures that THAT user has uploaded.

I think that might work, what do you think?


However the ONLY problem would be the "File" field. I don't know how I would determine where it is locatedon the server since its an obscure filename like hjfuh3ufh3pfhw3pfwu34243.jpg


Thanks for helping a beginner :D
Post Reply