DELETE FROM query via CSV contents MySQL

blubb0r

New Member
I have a CSV file uploaded to the same directory as the file containing the email addresses of people I want to delete from a table (all at once) in my database. The code I'm using echoes correctly but doesn't delete anything from the table. The CSV file is uploaded to the same directory as the file containing the code below. \[code\]<?php // Make a MySQL Connection mysql_connect("x", "x", "x") or die(mysql_error()); mysql_select_db("volunteers2012") or die(mysql_error()); mysql_query($sql); /********************************/ $addresses = file('deleteEmails.csv'); foreach($addresses as $address) { $safe_address = mysql_real_escape_string($address); $sql = "DELETE FROM vols2012 WHERE `email` = '$safe_address'"; $result = mysql_query($sql) or die(mysql_error()); } echo "DELETION A GREAT SUCCESS!"; ?>\[/code\]Round 2- Trying with a .txt file\[code\]<?php // Make a MySQL Connection mysql_connect("x", "x", "x") or die(mysql_error()); mysql_select_db("volunteers2012") or die(mysql_error()); mysql_query($sql); /********************************/ $addresses = "LOAD DATA LOCAL INFILE ('deleteEmails.txt')";foreach($addresses as $address) {$safe_address = mysql_real_escape_string($address);$sql = "DELETE FROM vols2012 WHERE (email = '$safe_address')";$result = mysql_query($sql) or die(mysql_error()); } echo "DELETION A GREAT SUCCESS!"; ?>\[/code\]I'm still getting the success echo, but with the error- Invalid argument supplied for foreach()
 
Back
Top