Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to create a php website that users log into and they can submit data to a MySQL database. How do I make it so the users can only see data they've submitted and not everyone else's data? Should I use:

Echo $_sessions[user][piece of data] 

Am I on the right track or is there an easier way to go about this? Is there a template or tutorial that shows how this is accomplished? It seems all the demos on the web show you how to log in then stop after that point. I've been researching for a while and have not come across a way to implement this.

share|improve this question

closed as too broad by AndyBursh, Ixrec, MichaelT, gnat, durron597 Sep 22 '15 at 13:52

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

The solution is to have two tables in your database. The first table, "user", can have two columns, "user-id" and "name". The second table, "data", can then have two columns, "submitted-by" and "info".

Whenever a user submits some new data, you update the "data" table with the information and the user-id of the user. This way, when the user wants to read all the data they have submitted, you can simply limit the query to only return records with their user-id

share|improve this answer
    
Thanks for the response. What PHP function would you use to call up the data? Filter_var_array? – Kevin S Sep 22 '15 at 9:43

Not the answer you're looking for? Browse other questions tagged or ask your own question.