<?php
//your database connection here...
//$_POST["Import"] this is data which you want to insert
$sql='';
if(isset($_POST["Import"]))
{
$filename=$_FILES["file_product"]["tmp_name"];
$type=$_FILES["file_product"]["type"];
//print_r($_FILES);
if($_FILES["file_product"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($emapData = fgetcsv($file, 50000, ",")) !== FALSE)
{
if($emapData[0]!="")
{
$t=mysql_escape_string(trim($emapData[2]));
$t1=strlen($t);
$city=mysql_escape_string(trim($emapData[7]));
$city1=strlen($city);
$state=mysql_escape_string(trim($emapData[8]));
$state1=strlen($state);
$zip=mysql_escape_string(trim($emapData[9]));
$zip1=strlen($zip);
$sql=rtrim($sql,',');
$sql ="insert into yourtable (phone_no, firstname, lastname,email, address1, address2, city, state, zip) values ('".mysql_escape_string(trim($emapData[1]))."','".mysql_escape_string(trim($emapData[2]))."','".mysql_escape_string(trim($emapData[3]))."','".mysql_escape_string(trim($emapData[4]))."','".mysql_escape_string(trim($emapData[5]))."','".mysql_escape_string(trim($emapData[6]))."','".mysql_escape_string(trim($emapData[7]))."','".mysql_escape_string(trim($emapData[8]))."','".mysql_escape_string(trim($emapData[9]))."')";
mysql_query($sql) or mysql_error(1);
}
}
fclose($file);
echo "CSV File has been successfully Imported";
}
else
echo "Invalid File:Please Upload CSV File";
}
?>
<html>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file_product" />
<input type="submit" name="Import" />
</form>
</html>
//your database connection here...
//$_POST["Import"] this is data which you want to insert
$sql='';
if(isset($_POST["Import"]))
{
$filename=$_FILES["file_product"]["tmp_name"];
$type=$_FILES["file_product"]["type"];
//print_r($_FILES);
if($_FILES["file_product"]["size"] > 0)
{
$file = fopen($filename, "r");
while (($emapData = fgetcsv($file, 50000, ",")) !== FALSE)
{
if($emapData[0]!="")
{
$t=mysql_escape_string(trim($emapData[2]));
$t1=strlen($t);
$city=mysql_escape_string(trim($emapData[7]));
$city1=strlen($city);
$state=mysql_escape_string(trim($emapData[8]));
$state1=strlen($state);
$zip=mysql_escape_string(trim($emapData[9]));
$zip1=strlen($zip);
$sql=rtrim($sql,',');
$sql ="insert into yourtable (phone_no, firstname, lastname,email, address1, address2, city, state, zip) values ('".mysql_escape_string(trim($emapData[1]))."','".mysql_escape_string(trim($emapData[2]))."','".mysql_escape_string(trim($emapData[3]))."','".mysql_escape_string(trim($emapData[4]))."','".mysql_escape_string(trim($emapData[5]))."','".mysql_escape_string(trim($emapData[6]))."','".mysql_escape_string(trim($emapData[7]))."','".mysql_escape_string(trim($emapData[8]))."','".mysql_escape_string(trim($emapData[9]))."')";
mysql_query($sql) or mysql_error(1);
}
}
fclose($file);
echo "CSV File has been successfully Imported";
}
else
echo "Invalid File:Please Upload CSV File";
}
?>
<html>
<form method="post" enctype="multipart/form-data">
<input type="file" name="file_product" />
<input type="submit" name="Import" />
</form>
</html>
Comments
Post a Comment