DELETE  not working but no errors

Posted on 2008-06-16
Last Modified: 2013-12-13

I have an unusual problem driving me nuts - I have a mailing database containing two tables, maillist and exclude.  I am uploading a list of emails to add to the exclude list and then, depending on whether a checkbox is ticked, also deleting the same addesses from the maillist.

The INSERT works fine, however, the DELETE operation fails to work, but there are no errors reported.

Any help will be appreciated.


Peter J
$fcontents = file ("../_ul/".$filename) ;

  echo "count ".count($fcontents)."<br>";


     echo "Error, no file or empty file";



  for($i=0; $i<count($fcontents); $i++) {

      $sql = "INSERT INTO exclude (email) VALUES ('$fcontents[$i]')";

      $result=mysql_query($sql)or die ("Could not execute query INSERT ".mysql_error());

      echo $i."Exclude list updated - ".$fcontents[$i]."  ".mysql_affected_rows()."<br>";



           for($i=0; $i<count($fcontents); $i++) {

                  $sqld="DELETE FROM maillist WHERE email = '$fcontents[$i]'";

                  $result=mysql_query($sqld) or die ("Could not execute query DELETE ".mysql_error());

                  //echo mysql_num_rows($result);

                  echo $i."Maillist entry deleted - ".$fcontents[$i]."  ".mysql_affected_rows()."<br>";


   } //ifdelete



Open in new window

Question by:petercircuit

Expert Comment

ID: 21791834
Does your script succesfully exit with die()? I think exit() is exactly the same but im not sure.
LVL 34

Expert Comment

by:Beverley Portlock
ID: 21791914
Check the obvious adn ensure that you are getting through the IF and the FOR loop. Change your code to be like this

 echo $_POST['delete_maillist'] ."<br>";


echo "passed the IF<br>";

           for($i=0; $i<count($fcontents); $i++) {

echo "in the FOR 'i' is $i<br>";

                  $sqld="DELETE FROM maillist WHERE email = '$fcontents[$i]'";

echo "qry is $sqld<br>";

                  $result=mysql_query($sqld) or die ("Could not execute query DELETE ".mysql_error());
                  //echo mysql_num_rows($result);
                  echo $i."Maillist entry deleted - ".$fcontents[$i]."  ".mysql_affected_rows()."<br>";
   } //ifdelete

What sort of output is generated?


Expert Comment

ID: 21792103
I think there are two possible reasons for this, i have highlighted those in the comments below.

// On line 16, check to make sure that you get value

// for "delete_maillist" and tis value is "on"



// check to make sure that "fcontents" is an array

// try printing this array using "print_r($fcontents)"

for($i=0; $i<count($fcontents); $i++)


Open in new window

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.


Author Comment

ID: 21800921
HI guys,

Thanks for the suggestions,  I have checked for the obvious errors -
if I change the field name to a none existant db field the query dies correctly
if I change the state of the check box the output correctly indicates that the deletion occured or not depending on checkbox state.
Everything apperas to be working except that the delete does not actually delete anything and the affected rows statment confirms this.
I have attached a section of the output generated
More help if possible please !!
Peter J


button2----Update Exclude Data


count 528

0Exclude list updated - 1

1Exclude list updated - 1

2Exclude list updated - 1

3Exclude list updated - 1

4Exclude list updated - 1



526Exclude list updated - 1

527Exclude list updated - 1

0Maillist entry deleted - 0

1Maillist entry deleted - 0

2Maillist entry deleted - 0

3Maillist entry deleted - 0

4Maillist entry deleted - 0

5Maillist entry deleted - 0

6Maillist entry deleted - 0

7Maillist entry deleted - 0



525Maillist entry deleted - 0

526Maillist entry deleted - 0

527Maillist entry deleted - 0

Disney Vacation Villas Mailer Exclude List Upload 


Open in new window


Accepted Solution

damuarth earned 500 total points
ID: 21820198
Hi peter,

I have made a trace of your code and the only apparent reason for this to happened is that the elements that are you trying to delete don't exist on the database...

if the elements does exist I recommend to add a link connection on your query:

mysql_query($sqld, $link)

some times when you have a lot of code and includes the implicit link is not the link that you think you are using.

Author Closing Comment

ID: 31467502
Thanks,  on re checking everything and setting up a very basic test with just a few addresses I realised I had been chasing a big red herring - somewhere along the line I had actually deleted the addresses in question.  Many thanks.

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This article discusses four methods for overlaying images in a container on a web page
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now