Welcome Guest, Not a member yet? Register   Sign In
tracking a user's updates to database
#1

[eluser]jshultz[/eluser]
If someone can tell me if I'm on the right path or not. I want to allow users the ability to update the database and post new items. However, I don't want them to have access to other people's items. In other words, they can only see what they've posted.

In this case, I have a table that lists users and another table that will contain a list of their posts with post name and date and the posts id(primary key) and then a column that will contain the users unique id (not username but the unique/primary key from the users table).

Now, I want to get the user's unique id into the posts table. My theory is that I can do it this way:

query the database for the logged in users username, that should give me one row as their should only be one user with that user name. when I find that row I should be able to get that unique id from the row and then when the user inserts records into the database i can join that insert with the value of their unique id.

the reason i want to use the unique id is because it will stay the same even if the user changes their username. it, by definition, will be unique.

Is my theory the hard way to do this? Is there a better more sensible way? Am I over thinking it?

Thanks in advance. Smile
#2

[eluser]pistolPete[/eluser]
Do you use the session class?
The you could store the unique id at login using
Code:
$this->session->set_userdata('unique_id', 123);

and retrieve it using
Code:
$unique_id = $this->session->userdata('unique_id');




Theme © iAndrew 2016 - Forum software by © MyBB