Page 1 of 1

Delete multiple users

Posted: Mon Mar 08, 2004 1:10 pm
by maqmus
Hi !
I'm trying to work on a file where I store data about my e-mail subscribers (e-mail, IP and registration date). Now with checkboxes in a form I want to select some of them to be deleted.

I get an array with their info(e-mail address) in $delete_users, and I'm using this script.

Code: Select all

<?
$delete_users = $_POST['$delete_users'];
$file = $fullpath."my_list.php"; 
$filedat = file($file); 
while(list(,$v) = each($delete_users)) { 
foreach($filedat as $value){ 
list($e_mail,$_ip,$reg_date) = explode("|",$value); 
if ($e_mail!=$v){ 
$data = "$e_mail|$_ip|$reg_date|\n";} 
else $data = ""; 
$fp = fopen($file,"w"); 
fputs($fp,$data); 
fclose($fp); } 
} 
?>
The problem is it prints the full list as many times as values are in $delete_users, with one deletation on each. What should I do to print only once the list with all the deletion at a time?

I understand why this happens but can“t find the way to make it work correctly.

Posted: Mon Mar 08, 2004 4:34 pm
by markl999
Try something like this instead.

Code: Select all

<?php
if(!empty($_POST['delete_users'])){
  $file = $fullpath.'mylist.php';
  $filedat = file($file);
  foreach($filedat as $dat){
    list($e_mail, $_ip, $reg_date) = explode('|', $dat);
    if(!in_array($e_mail, $_POST['delete_users'])){
      $data[] = trim($e_mail.','.$_ip.','.$reg_date);
    }
  }
  if(!empty($data)){
    $fp = fopen($file, 'w');
    fputs($fp, join("\n", $data));
    fclose($fp);
  }
}
?>

Posted: Mon Mar 08, 2004 6:21 pm
by maqmus
Just what I needed, works great. :lol:

Thank you.