
I try to import excel file which contains data date(yyyy-mm-dd) into mysql database in php. But it not insert the data in mysql.
Code
$fp = fopen("data.csv",'w');
fwrite($fp,ob_get_contents());
fclose($fp);
//echo"----";
ob_end_clean();
//connect to the database
$connect = mysql_connect("localhost","root","");
mysql_select_db("DBA",$connect); //select the table
//$file = $_FILES['data.csv']['tmp_name'];
$handle = fopen('data.csv',"r");
//loop through the csv file and insert into database
GLOBAL $data;
do {
if($data[0]!="")
{
mysql_query("INSERT INTO productsegmentmaster VALUES ( '$data[0]', '$data[1]','$data[2]')");
}
} while ($data = fgetcsv($handle,1000,"*","'"));
}
fclose($handle);
echo"<script>alert('File $path Imported Successfully')</script>";
unlink('data.csv');
unlink($path);
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.