Import a CSV File Using PHP and MySQL

 <?//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 contacts_tmp (contact_first, contact_last, contact_email) VALUES
(
‘”.addslashes($data[0]).”‘,
‘”.addslashes($data[1]).”‘,
‘”.addslashes($data[2]).”‘
)
“);
}

} while ($data = fgetcsv($handle,1000,”,”,”‘”));

?>

Choose your file:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s