Delete user completely [closed]

谁说胖子不能爱 提交于 2019-12-10 12:16:46

问题


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.

  1. user
  2. albums - user_id
  3. block - user1_id
  4. blogdata_comments - comment_poster
  5. blogdata_feedback - feedback_userid
  6. friends - user1_id or user2_id
  7. messages - message_creator OR message_target
  8. notifications - notification_targetuser OR notification_triggeredby
  9. photo_comments - photo_comment_poster
  10. streamdata - streamitem_creator OR streamitem_target
  11. streamdata_comments - comment_poster
  12. streamdata_feedback - feedback_userid
  13. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!