I am trying to import data from csv file, which has the following format:
173,antony,xds1079,Antony,Pran,Pran Antony,,452522252,,,,antpran@hotmail.com,,,,,Yes,Yes,No,pricelist.xls
18,john,smithison22,John,Smith,Smith Jon,,545455726,,,,johnsmith01@in.com,,,,,Yes,Yes,No,pricelist.xls
22,nikolas,Brand44eBerg,Nikolas,Brandeberg,Brandeberg and sons ,,454554552,,,,brand88@freemail.co.uk,,,,,Yes,Yes,No,pricelist.xls
When inserted it in mySQL, the last field in the first row, contained both pricelist.xls and 18. But the 18 should go in the next row, since it is the id field.
Here is the php code that I used:
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 customers_tmp (id,username, password, firstname, lastname, companyname, companyposition, phone1, phone2, mobilephone, fax, email, address, afm, doy, website, active, wholesaling , wholesaling_bulk , pricecatalog) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."',
'".addslashes($data[3])."',
'".addslashes($data[4])."',
'".addslashes($data[5])."',
'".addslashes($data[6])."',
'".addslashes($data[7])."',
'".addslashes($data[8])."',
'".addslashes($data[9])."',
'".addslashes($data[10])."',
'".addslashes($data[11])."',
'".addslashes($data[12])."',
'".addslashes($data[13])."',
'".addslashes($data[14])."',
'".addslashes($data[15])."',
'".addslashes($data[16])."',
'".addslashes($data[17])."',
'".addslashes($data[18])."',
'".addslashes($data[19])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
//
//redirect
header('Location: import.php?success=1'); die;
}
Does anyone know what I should do so the id can go in next line and not in the last field?
In case that someone else may need this solution, here is how I solved my problem:
Regards,Zoran