I am trying to create a CSV importer for my website. I need to import some campaigns using a CSV file into my MySQL database.
The CSV file has 12 titles, but I only want to import the data from title 1, 3, 5, 6 and 8. The code below imports the csv file, but, it places the data for each title in the wrong places in the database.
Please could someone tell me where the error is?
Thanks -
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
//loop through the csv file and insert into database
do {
if ($data[0]) {
mysql_query("INSERT INTO campaigns (campaignname, url, requirements, rate, countrys) VALUES
(
'".addslashes($data[1])."',
'".addslashes($data[3])."',
'".addslashes($data[5])."',
'".addslashes($data[6])."',
'".addslashes($data[8])."'
)
");
}
} while ($data = fgetcsv($handle,0,",","'"));
//
//redirect
header('Location: import.php?success=1'); die;
}