问题
If a user or an admin wanted to delete a user completely from the site. how would you go about setting a query to remove that user from every table/subtables where the users id is contained. Here is the list of my tables with the subtables where the possible id of an individual user could be.
- user
- albums - user_id
- block - user1_id
- blogdata_comments - comment_poster
- blogdata_feedback - feedback_userid
- friends - user1_id or user2_id
- messages - message_creator OR message_target
- notifications - notification_targetuser OR notification_triggeredby
- photo_comments - photo_comment_poster
- streamdata - streamitem_creator OR streamitem_target
- streamdata_comments - comment_poster
- streamdata_feedback - feedback_userid
- userphotos - photo_ownerid
回答1:
@Dave i could be way off the mark with this but i think you could do something like this which would also stop the user from creating a new account.
You would obviously need to make your own version of the very basic code below but it should work?
EDIT just thought ud need their ip already
$db = new mysqli ('host', 'username', 'password', 'database');
$removeUser = "DELETE FROM (user, albums, block, and-so-on) WHERE `user-id`='$user'";
if(removeUser = $db->query($removeUser)){
$ipAddr = $_SESSION['REMOTE_ADDR'];
$banList = "INSERT INTO banned (ipAddr) VALUES ('$ipAddr')"
die($user . 'removed from all tables');
if($banList = $db->query($banList)){
die($user . 'Added to banned list');
}else{
die('Error adding ' . $user . ' to banned list');
}
}else{
die ('Unable to remove user from all tables');
}
来源:https://stackoverflow.com/questions/25454522/delete-user-completely