Allowing users to edit ONLY their own data

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
imderek
Forum Newbie
Posts: 12
Joined: Thu Jul 24, 2008 9:04 am

Allowing users to edit ONLY their own data

Post by imderek »

I'm building a site that allows all visitors to view property listings made by multiple users (anyone who registers and is approved basically). It's been easy so far setting up the registration area, the listings viewing area, and the area for adding new listings. The question is, how can I best construct an admin area where, once logged in, each user is greeted with a "dashboard" of sorts which displays property listings created by said user ONLY (which they can then edit)?

I should mention (though you've probably already assumed) that each property listing has a unique id and a created_by_user_id, and I'm using MySQL.

Any ideas would be greatly appreciated. Thanks!
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Allowing users to edit ONLY their own data

Post by califdon »

imderek wrote:I'm building a site that allows all visitors to view property listings made by multiple users (anyone who registers and is approved basically). It's been easy so far setting up the registration area, the listings viewing area, and the area for adding new listings. The question is, how can I best construct an admin area where, once logged in, each user is greeted with a "dashboard" of sorts which displays property listings created by said user ONLY (which they can then edit)?

I should mention (though you've probably already assumed) that each property listing has a unique id and a created_by_user_id, and I'm using MySQL.

Any ideas would be greatly appreciated. Thanks!
Should be pretty straightforward. If every property listing record includes a created_by_user_id field, and your user is logged in, you are probably storing the login as a session variable, so just use that in the WHERE clause of your SQL query to limit the results to those with that user's id. Am I missing something?

Why don't you show us the SQL statement you are using now.
Post Reply