Guest User

Untitled

a guest
Aug 10th, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. Why is my data getting inserted twice? PHP/MySQL
  2. 015826136@domain.com,2010-11-08 14:10:35
  3. 01DETAIL@domain.com,2011-11-01 20:14:21
  4. 01krisp10@domain.com,2010-11-08 15:00:09
  5. 01luis@domain.com,2010-11-08 15:00:09
  6. 01tthomas@domain.com,2010-11-08 15:09:13
  7. 02570734@domain.com,2011-10-10 11:44:54
  8. 02arman02@domain.com,2010-11-08 14:53:26
  9. 03091980@domain.com,2010-11-08 14:45:09
  10. 03331025@domain.com.com,2010-11-08 14:45:09
  11.  
  12. if ( isset($_POST["step"]) && $_POST["step"] == '2' ) {
  13.  
  14. if ( isset($_FILES["file"])) {
  15.  
  16. if ($_FILES["file"]["error"] == 0) {
  17. $name = $_FILES['file']['name'];
  18. $ext = strtolower(end(explode('.', $_FILES['file']['name'])));
  19. $type = $_FILES['file']['type'];
  20. $tmpName = $_FILES['file']['tmp_name'];
  21.  
  22. // check the file is a csv
  23. if($ext === 'csv'){
  24. if(($handle = fopen($tmpName, 'r')) !== FALSE) {
  25.  
  26. $field = $_POST['field'];
  27. //clear the import table
  28. mysql_query("TRUNCATE table iContact_import");
  29.  
  30. //loop through the CSV
  31. while(($data = fgetcsv($handle, 300, ',')) !== FALSE) {
  32. //$info = explode(",", $line);
  33. //echo $info[0].'<br/>';
  34. mysql_query("INSERT iContact_import (email,field) values ('".$data[0]."','".$field."')");
  35. }
  36.  
  37. echo '<h3 style="color:green;">Database is prepped for new subscribers</h3>';
  38. echo '<p><a href="icontact_process.php?step=3">Click here to update subscriptions</a></p>';
  39.  
  40. }
  41.  
  42. } else {
  43. echo '<p>File is not a CSV. Please use another field with CSV values and extension.</p>';
  44. }
  45.  
  46. } else {
  47. echo "Error: " . $_FILES["file"]["error"] . "<br />";
  48. }
  49.  
  50. } else {
  51. echo '<p>Please upload a CSV file with email addresses to import.</p>';
  52. }
  53. }
  54.  
  55. ALTER TABLE `my_table` ADD UNIQUE KEY (`email`);
Add Comment
Please, Sign In to add comment