Note: Dont Forget To Save Excel File in .Cvs Format Before Executing This Code
Note: Dont Forget To Save Excel File in .Cvs Format Before Executing This Code
",$fname); if(strtolower($chk_ext<1>) == "csv") { $filename = $_FILES<'sel_file'><'tmp_name'>; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $sql = "INSERT into user(name,email,phone) values('$data<0>','$data<1>',' $data<2>'"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } <form action='<?php echo $_SERVER<"PHP_SELF">;?>' method='post'> Import File : <input type='text' name='sel_file' size='20'> <input type='submit' name='submit' value='submit'> </form>
Note : Dont forget to save excel file in .cvs format before executing this code.
How to import the CSV/Excel file in to MYSQL database via using fgetcsv() function
By Mahesh