Deleting user

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
riiel
Forum Newbie
Posts: 16
Joined: Sat Apr 25, 2009 3:29 am

Deleting user

Post by riiel »

i have script what delete all user who are blocked.
But I want a script where I can choose which blocked users can I delete.

Delete all blocked user script:

Code: Select all

<SCRIPT TYPE="text/javascript" LANGUAGE="javascript" SRC="blocker.php">
</SCRIPT>
 
<?
if($users->checkULevel() == 3)
{
    if($_GET["omg"])
    {
        $q = $db->dbQuery("SELECT * FROM `comments` WHERE `type` = '1' ORDER BY `atime` ASC");
        while($arr = MySQL_Fetch_Array($q))
        {
            unset($pID, $saatja, $saaja, $comment, $atime);
            $pID = $arr["pid"];
            $saatja = $arr["uid2"];
            $saaja = $arr["uid1"];
            $comment = $arr["comment"];
            $atime = $arr["atime"];
            $db->dbQuery("INSERT INTO `tenpoints` VALUES (0, '".$saatja."', '".$saaja."', '".$pID."', '".$comment."', '".$atime."')");
        }
    }
 
    if($_POST["doit"] == "ok")
    {
        include("Class/CleanUp.class.php");
        $cleanup = &new CleanUp();
        $cleanup->delBlockedUsers();
    }
    ?>
    <form action="?pID=35" method="POST">
    <input type="hidden" name="doit" value="ok" />
    <input type="submit" value="Delete blocked users" class="input" />
    </form>
    <?
}
?>
 
Cleanup script:

Code: Select all

<?
class CleanUp extends Pictures
{
    function delUser($uID)
    {
        $this->delUserPictureFiles($uID);
        $this->dbQuery("DELETE FROM `users` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `bpoints` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `comments` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `comments` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `friends` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `friends` WHERE `friend` = '".$uID."'");
        $this->dbQuery("DELETE FROM `gallup_votes` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `inbox` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `inbox` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `outbox` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `outbox` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `jackpot_history` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `jackpot_today` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `logins` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `mode_logs` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `mode_pics` WHERE `mid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `mode_tenpoints` WHERE `mid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `mode_top` WHERE `mid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `moderators` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `pictures` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `ratings` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `ratings` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `ratings2` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `pictures_points` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `specials` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `specials` WHERE `mid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `top_cache` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_blocks` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_blocks` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_cash` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_couples` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_couples` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `descriptions` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `descriptions` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_profile` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_statuses` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_views` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_views` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_views2` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_views2` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_views3` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `forum_topics` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `forum_posts` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_pset` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_notifymsg` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_messengers` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `smschat` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `memo` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `scraps` WHERE `uid1` = '".$uID."'");
        $this->dbQuery("DELETE FROM `scraps` WHERE `uid2` = '".$uID."'");
        $this->dbQuery("DELETE FROM `c_members` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `communities` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `c_comments` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `c_forum` WHERE `uid` = '".$uID."'");
        $this->dbQuery("DELETE FROM `users_activity` WHERE `uid` = '".$uID."'");
        $this->delUserCommunities($uID);
    }   
 
    function delUserCommunities($uID)
    {
        $q = $this->dbQuery("SELECT * FROM `communities` WHERE `uid` = '".$uID."'");
        while($arr = mysql_fetch_array($q))
        {
            $cID = $arr["cID"]; 
            $this->dbQuery("DELETE FROM `communities` WHERE `cid` = '".$cID."'");
            $this->dbQuery("DELETE FROM `c_members`  WHERE `cid` = '".$cID."'");
            $this->dbQuery("DELETE FROM `c_comments` WHERE `cid` = '".$cID."'");
            $this->dbQuery("DELETE FROM `c_forum` WHERE `cid` = '".$cID."'");
        }
    }
 
    function delUserPictureFiles($uID)
    {
        $q = $this->dbQuery("SELECT `pid` FROM `pictures` WHERE `uid` = '".$uID."'");
        while($arr = MySQL_fetch_Array($q))
        {
            unlink($this->thumbImgFile($arr["pid"]));
            unlink($this->imgFile($arr["pid"]));
        }
    }
 
    function <span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>()
    {
        $q = $this->dbQuery("SELECT `pid` FROM `tenpoints`");
        while($arr = MySQL_Fetch_Array($q))
        {
            if(!$this->imageExists($arr["pid"]))
                $this->dbQuery("DELETE FROM `tenpoints` WHERE `pid` = '".$arr["pid"]."'");
        }
    }
 
    function delOldUsers()
    {
        $q1 = $this->dbQuery("SELECT * FROM `users_statuses` WHERE ".time()."-`lastclick` > 15778463");
        while($arr1 = MySQL_Fetch_Array($q1))
        {
            $this->delUser($arr1["uid"]);
        }
    }
 
    function delBlockedUsers()
    {
        $q1 = $this->dbQuery("SELECT * FROM `users` WHERE `status` >0");
        while($arr1 = MySQL_Fetch_Array($q1))
        {
            $this->delUser($arr1["uid"]);
        }
    }
}
?>
Script where i can see blocked users (in this script i want delete blocked users):

Code: Select all

<?
if($users->checkULevel() == 3)
{
    ?>
<style type="text/css">
<!--
.style1 {
    font-size: 16px;
    font-weight: bold;
}
-->
</style>
 
<font class="contentFont">
</font>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr>
    <td>
      <div align="center">
        <table width="50%" height="0%" border="0" cellpadding="5" cellspacing="1" class="tabelBorder2">
          <tr bgcolor="#E6E9EE">
            <td height="100%" colspan="5" bgcolor="#171717"><div align="center" class="style1">Blocked users</div></td>
          </tr>
          <tr bgcolor="#E6E9EE">
          <td width="30%" align="left" bgcolor="#202020">Picture</td>
            <td width="30%" align="left" bgcolor="#202020">User</td>
            <td width="30%" align="left" bgcolor="#202020">Age</td>
            <td width="50%" bgcolor="#202020"><div align="right">Registeres time </div></td>
            <td width="50%" bgcolor="#202020"><div align="right">Delete </div></td>
          </tr>
          <?
          $rida = 1;
          $col1 = '#F7F9FB';
          $col2 = '#EEF2F9';
          $q = $db->dbQuery("SELECT * FROM `users` WHERE `status` >= '1' ORDER BY `atime` DESC LIMIT 100");
          while($arr = MySQL_Fetch_Array($q))
          {
          ?>
          
          <?
    $pictures = &new Pictures();
    while($arr = MySQL_Fetch_Array($q))
    {
        unset($picStuff);
        if($users->getUserPicCount($arr["uid"]) > 0)
        {
            $bestPic = $pictures->userBestPic($arr["uid"]);
            $picStuff = '<a href="?pID=14&pic='.$bestPic.'"><img src="Modules/Thumb.php?pID='.$bestPic.'" border=0></a>';
        }
        else
            $picStuff = "<img src=\"gfx/error.png\" border=0>";
        
        ?>
          
          <tr bgcolor="<?=($rida?$col1:$col2);?>">
            <td width="30%" align="left" bgcolor="#2b2b2b"><?=$picStuff;?></td>
            <td width="30%" align="left" bgcolor="#2b2b2b"><?=$users->getUser4($arr["uid"]);?></td>
            <td width="30%" align="left" bgcolor="#2b2b2b"><?=$users->getAge($arr["uid"]);?></td>
            <td width="50%" bgcolor="#2b2b2b">              <div align="right">
                <font class="contentFont"><?=date('d.m.Y  H:i', $arr["atime"]);?></font>
            </div></td>
            <td width="30%" align="left" bgcolor="#2b2b2b"><form action="?pID=75" method="POST">
    <input type="hidden" name="doit" value="ok" />
    <input type="submit" value="Delete user" class="input" />
    </form></td>
          </tr>
          <?
              $rida = !$rida;
          }
          ?>
                  </table>
    </div></td>   
          </tr>
        </table>
 
<?
}
?>
<?
}
?>
 
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Deleting user

Post by JakeJ »

Unless you really need to conserve space, it's almost always better to add an additional field to indicate whether or not a user is active or not. Then you can change change the active bit. Very easy.
riiel
Forum Newbie
Posts: 16
Joined: Sat Apr 25, 2009 3:29 am

Re: Deleting user

Post by riiel »

but how i can do this ?
riiel
Forum Newbie
Posts: 16
Joined: Sat Apr 25, 2009 3:29 am

Re: Deleting user

Post by riiel »

Can somebody help me ? :S
JakeJ
Forum Regular
Posts: 675
Joined: Thu Dec 10, 2009 6:27 pm

Re: Deleting user

Post by JakeJ »

Add a boolean type field to your table (name it 'active' or something else useful). Default should be 0. Change your queries that delete records to UPDATE queries that change the 'active' field to 1.

Then in other queries that use active users, just make sure that the 'active' field != 1.

UPDATE table SET active = 1 WHERE field_name = '$variable'

I hope that helps.
Post Reply