views:

91

answers:

1

I run a forum which I built myself. Ok so all users have the opportunity to delete themselves.

But all their threads and posts will remain. But right now where it should say their username it's just blank.

How should I handle this?

Should I make a new user and call it e.g. "deleted user" and assign all threads/posts to that ID when they delete themselves? Or should I just check if the user ID exist if not print e.g. "deleted user" as username?

What's the smartest way? Any other ways tell me.

Thanks!

p.s (i'm not a native english speaker, looked up some fancy words on a online dictionary)

+7  A: 

I would suggest not actually deleting the user. You could simply add a column to the users table such as:

ALTER TABLE users ADD COLUMN (is_active TINYINT(1) NOT NULL DEFAULT 1);

Then when you "delete" a user, simply mark them as inactive:

UPDATE users SET is_active = 0 WHERE users.id = 7;

For user listings, and account access you would check the is_active status. For displaying of data such as posts and what not, you'd not care about their active status, youd just grab the name from the table.

hobodave
good idea! thanks
My idea exactly. Just be sure that you don't leave any backdoors open for that user (or any private data for that user) on the DB. Any requests to log in as user or make changes as the user or anything else like that need to check against that "is active" flag. Any users may delete themselves because they are trying to become anonymous (trouble with an ex, perhaps), so any other tables that include things like their email, pictures, or anything else for that matter, need to be purged. It is better to have that show up as blank or NULL then violate their privacy.
Anthony