<?php
//connect to the database
$connect = mysql_connect("localhost","root","");
//select the table
mysql_select_db("mydatabase",$connect);
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]){
$query = "INSERT INTO contacts set post_title='".$data[1]."',post_content='".$data[2]."',category='".$data[3]."',tags='".$data[4]."',Post_author='".$data[5]."',post_date='".$data[6]."',post_date_gmt='".$data[7]."',post_excerpt='".$data[8]."',post_status='".$data[9]."',video='".$data[10]."',address='".$data[11]."',geo_latitude='".$data[12]."',geo_longitude='".$data[13]."',phone='".$data[14]."',st_date='".$data[15]."',st_time='".$data[16]."',end_date='".$data[17]."',email='".$data[18]."',alive_days='".$data[19]."',website='".$data[20]."',twitter='".$data[21]."',facebook='".$data[22]."',reg_desc='".$data[23]."',organizer_name='".$data[24]."',organizer_email='".$data[25]."',organizer_logo='".$data[26]."',organizer_address='".$data[21]."',organizer_contact='".$data[22]."',organizer_website='".$data[23]."',organizer_mobile='".$data[24]."',featured_type='".$data[25]."',map_view='".$data[26]."',IMAGE='".$data[27]."'";
mysql_query($query);}
}while ($data = fgetcsv($handle,1000));
//redirect
header('Location: import.php?success=1'); die;}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File</title>
</head>
<body>
<?php if (!empty($_GET['success'])) { echo "<b>Your file has been imported.</b><br><br>"; } ?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
Choose your file: <br />
<input name="csv" type="file" id="csv" />
<input type="submit" name="Submit" value="Submit" />
</form>
</body>
</html>

Join the conversation! Your thoughts help the community grow.