Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Why is my data getting inserted twice? PHP/MySQL
- 015826136@domain.com,2010-11-08 14:10:35
- 01DETAIL@domain.com,2011-11-01 20:14:21
- 01krisp10@domain.com,2010-11-08 15:00:09
- 01luis@domain.com,2010-11-08 15:00:09
- 01tthomas@domain.com,2010-11-08 15:09:13
- 02570734@domain.com,2011-10-10 11:44:54
- 02arman02@domain.com,2010-11-08 14:53:26
- 03091980@domain.com,2010-11-08 14:45:09
- 03331025@domain.com.com,2010-11-08 14:45:09
- if ( isset($_POST["step"]) && $_POST["step"] == '2' ) {
- if ( isset($_FILES["file"])) {
- if ($_FILES["file"]["error"] == 0) {
- $name = $_FILES['file']['name'];
- $ext = strtolower(end(explode('.', $_FILES['file']['name'])));
- $type = $_FILES['file']['type'];
- $tmpName = $_FILES['file']['tmp_name'];
- // check the file is a csv
- if($ext === 'csv'){
- if(($handle = fopen($tmpName, 'r')) !== FALSE) {
- $field = $_POST['field'];
- //clear the import table
- mysql_query("TRUNCATE table iContact_import");
- //loop through the CSV
- while(($data = fgetcsv($handle, 300, ',')) !== FALSE) {
- //$info = explode(",", $line);
- //echo $info[0].'<br/>';
- mysql_query("INSERT iContact_import (email,field) values ('".$data[0]."','".$field."')");
- }
- echo '<h3 style="color:green;">Database is prepped for new subscribers</h3>';
- echo '<p><a href="icontact_process.php?step=3">Click here to update subscriptions</a></p>';
- }
- } else {
- echo '<p>File is not a CSV. Please use another field with CSV values and extension.</p>';
- }
- } else {
- echo "Error: " . $_FILES["file"]["error"] . "<br />";
- }
- } else {
- echo '<p>Please upload a CSV file with email addresses to import.</p>';
- }
- }
- ALTER TABLE `my_table` ADD UNIQUE KEY (`email`);
Add Comment
Please, Sign In to add comment