Solved

DELETE  not working but no errors

Posted on 2008-06-16
6
195 Views
Last Modified: 2013-12-13
Hi,

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.

regards

Peter J
$fcontents = file ("../_ul/".$filename) ;
  echo "count ".count($fcontents)."<br>";
  if(!$fcontents){
     echo "Error, no file or empty file";
     exit;
     }
  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
 
 
   if($_POST['delete_maillist']=="on"){
           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>";
 
           }//for
   } //ifdelete
 
  $done="TRUE";
}//ifbutton2

Open in new window

0
Comment
Question by:petercircuit
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 1

Expert Comment

by:kambo_rambo
ID: 21791834
Does your script succesfully exit with die()? I think exit() is exactly the same but im not sure.
0
 
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>";

   if($_POST['delete_maillist']=="on"){

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>";
 
           }//for
   } //ifdelete


What sort of output is generated?


 
0
 

Expert Comment

by:asimzeeshan
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"
if($_POST['delete_maillist']=="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

0
Comparison of Amazon Drive, Google Drive, OneDrive

What is Best for Backup: Amazon Drive, Google Drive or MS OneDrive? In this free whitepaper we look at their performance, pricing, and platform availability to help you decide which cloud drive is right for your situation. Download and read the results of our testing for free!

 

Author Comment

by:petercircuit
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 !!
regards
Peter J
filename----lv_fail.txt
delete_maillist----on
button2----Update Exclude Data
done----
count 528
0Exclude list updated - rainbowclinic@totalise.com 1
1Exclude list updated - health@circuit-consultants.com 1
2Exclude list updated - shabir.a.suleman@delpiauto.com 1
3Exclude list updated - ccl-producttion@hubuk.com 1
4Exclude list updated - baranozturk@istslr.com 1
......
.......
526Exclude list updated - mogee@instantemail.t-mobile.co.uk 1
527Exclude list updated - joe@mx.litedealz.com 1
0Maillist entry deleted - rainbowclinic@totalise.com 0
1Maillist entry deleted - health@circuit-consultants.com 0
2Maillist entry deleted - shabir.a.suleman@delpiauto.com 0
3Maillist entry deleted - ccl-producttion@hubuk.com 0
4Maillist entry deleted - baranozturk@istslr.com 0
5Maillist entry deleted - booklets@hubuk.com 0
6Maillist entry deleted - webmaster@rdinstruments.com 0
7Maillist entry deleted - sales@circuit-consultants.com 0
.....
.....
525Maillist entry deleted - newsletter@support.iii.co.uk 0
526Maillist entry deleted - mogee@instantemail.t-mobile.co.uk 0
527Maillist entry deleted - joe@mx.litedealz.com 0
Disney Vacation Villas Mailer Exclude List Upload 
 

Open in new window

0
 

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:petercircuit
ID: 31467502
Hi,
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.
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how to solve "recursive" database tables 2 59
Create a Calendar table 29 45
Why is my select returning NaN 23 40
Importing from CSV to SSMS 2 13
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

751 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