hey guys so ive been asked to add an import csv function to my contacts page.
<?php
require "connection.php";
if ($_FILES[csv][size] > 0) {
//get the csv file
$file = $_FILES[csv][tmp_name];
$handle = fopen($file,"r");
if ($data[0]) {
mysql_query("INSERT INTO contact (fname,lname,email) VALUES
(
'".addslashes($data[0])."',
'".addslashes($data[1])."',
'".addslashes($data[2])."'
)
");
}
} while ($data = fgetcsv($handle,1000,",","'"));
}
?>
i found this coding on the net and just want some clarification.
if($data[0])
checks if the first "column" of a csv file exists?- stumbled on a site that said
addslashes
isnt good but did not elaborat. why isnt it good? - say my first column is
id
and itsauto-increment
do i add column id in the insert query? ->contact (id,fname,lname,email)
- what if the csv file has header? how to code to check if theres header and if there is ignore the header.
whats the
1000
in thefgetcsv($handle,1000,",","'"))
?thanks in advance!