aaronmc123 Posted December 19, 2011 Share Posted December 19, 2011 How to show the username of the person who uploaded something? I know how to make the upload script etc. but what is the script needed for the person's username and where do I put it? Thanks. Quote Link to comment Share on other sites More sharing options...
Psycho Posted December 19, 2011 Share Posted December 19, 2011 There is no way for us to answer this for you as we know nothing about your current application. Are you storing any information about the uploads now that is separate from the files themselves? If you are storing information in a database, then you would want to add an additional column in the table to store a foreign key reference back to the user who uploaded the file. If you have a user based system then you should have some means of knowing who the user is (SESSION, COOKIE< etc.) - so you should already have the users ID. So, when the user submits a file you would get that value and include it with the other data you are storing. Again, no idea how to tell you actually how to do this since I have no knowledge of your current code. Then when you display the file (or more likely a link to the file) you would query the database for the information you were previously displaying and you would use the foreign key reference for the user ID to join the users table to also get the username. Quote Link to comment Share on other sites More sharing options...
Ivan Ivković Posted December 20, 2011 Share Posted December 20, 2011 Since I know nothing about your code, I'll improvise. 1. In your login, you should have a user_id. ($_SESSION['user_id']) 2. In the database, the uploads table should have columns uploader_id. When you upload the file, the query should contain: $query = "INSERT INTO uploads SET uploaded_file = $file, uploader_id = $_SESSION['user_id'] "; 3. When printing out the upload, the query should have this: $query = "SELECT uploaded_file_id, uploaded_file, username FROM uploads JOIN users ON uploads.uploader_id=users.user_id"; And then when you print out username, you'll get your user who uploaded the file. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.