How to upload excel file to mysql in php -
i trying upload excel file using html input tag, mysql database using php. result whole lot of caricature in database. time works correctly when create .csv file notepad , upload it.
if(isset($_post['submit_excel'])){ if(!is_uploaded_file($_files['file_excel']['tmp_name'])){ echo '<script type="text/javascript">function hidemsg(){ document.getelementbyid("popup_no_f").style.visibility = "hidden"; } document.getelementbyid("popup_no_f").style.visibility = "visible"; window.settimeout("hidemsg()", 4000); </script>'; } else { $filename = $_files['file_excel']['name']; $extension = pathinfo($filename, pathinfo_extension); if ($extension == 'xlsx' || $extension == 'csv' || $extension == 'xls') { if($_files['file_excel']["size"] > 0) { $handle = fopen($_files['file_excel']['tmp_name'], "r"); $count = 0; while (($data = fgetcsv($handle, 1024, ",")) !== false) { $count++; if ($count>1) { if (empty(data[0]) && empty(data[1]) && empty(data[2]) && empty(data[3]) && empty(data[4]) ){ echo alert(); }else{ do{ $bookuniqueid = uniqueid(); $query = "select book_unique_id books_tbl book_unique_id= '$bookuniqueid' "; $query_run = mysqli_query($link, $query); $numrowscheck = mysqli_num_rows($query_run); } while ( $numrowscheck > 0); $import ="insert books_tbl (book_name, book_authors, book_category, book_quantity, book_cd, book_unique_id, book_uploaded_admin, book_created_date, book_quant_stat) values ('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]', '$bookuniqueid', '$adminname', current_date, '$data[3]' )"; mysqli_query($link, $import); } } } fclose($handle); echo '<script type="text/javascript">function hidemsg(){ document.getelementbyid("popup").style.visibility = "hidden"; } document.getelementbyid("popup").style.visibility = "visible"; window.settimeout("hidemsg()", 4000); </script>'; } } else { echo '<script type="text/javascript">function hidemsg(){ document.getelementbyid("popup_ext").style.visibility = "hidden"; } document.getelementbyid("popup_ext").style.visibility = "visible"; window.settimeout("hidemsg()", 4000); </script>'; } }
Comments
Post a Comment