SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I'm having this problem with my script, in the fact that it isn't deleting more than one email address. And if there aremore than one email address in the textarea then none get deleted. Here is my code:

    Code:
    if($ent == "") {
    errorMsg("You must enter at least one email address.");
    } else {
    
    $ents = explode("\n", $ent);
    if(count($ents) > 0) { 
    $delidStr = implode(",",$ents); 
    }
    $del = mysql_query("DELETE from emails WHERE listID='$listID' AND email in ('$delidStr')");
    $num = mysql_affected_rows();
    if($del) {
    msg("$num emails have been deleted.");
    } else {
    errorMsg("There was an error deleting the emails from the database.");
    print mysql_error();
    }
    }
    I have a working copy of this, however it doesn't have the listID='$listID' part and it also doesn't use the emails but instead uses an ID. THat is for a different function so it wouldn't work with this.

    ANyway, does anyone know why this would only delete 1 email address, but is more than 1 is supplied it deletes none?

    Thanx
    Peter

  2. #2
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Don't worry, I found a solution and I'll share it incase anyone else gets this problem:

    Code:
    if($ent == "") {
    errorMsg("You must enter at least one email address.");
    } else {
    
    $ents = explode("\n", $ent);
    if(count($ents) > 0) { 
    $delidStr = implode("','",$ents); 
    }
    $del = mysql_query("DELETE from emails WHERE listID='$listID' AND email in ('$delidStr')");
    $num = mysql_affected_rows();
    if($del) {
    msg("$num emails have been deleted.");
    } else {
    errorMsg("There was an error deleting the emails from the database.");
    print mysql_error();
    }
    }
    I had to add 's around $delidStr part in the delete query and I have to $delidStr = implode("','",$ents); add the 's there aswell.

    Just to let you know.

    Thanks
    peter


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •