read excel file and insert into mysql database using php

How to read and insert an excel file data into MySQL.

Welcome back to shortlearner.com, in this post we will learn how to read an excel file and insert the excel data into MySQL with the help of PHP Excel library.

read and insert an excel file data into MySQL

 Now a days i am working on a project of one of my client and he has a bulk amount of data in excel(.xlsx) format.
he wants to insert all his data into database using single process to save his time.

Also Read :
Get Domain name from URL
How to Send Attachment on mail using PHP.
PHP Login Script With Remember me.
Change password using javascript, php and mysqli.
Password and Confirm Password Validation Using JavaScript
Check Email is Already Registered in Database using Ajax and JavaScript.

Advertisement

How to hide extension of html and php file.?

Hence, we have created a process which fulfills our client requirement.
So, in this post we are going to share the way

how we can achieve the same. You can also try the same way which will save your time and easy to implement.


Below is the example of inserting excel data into mysql with the help of PHPExcel library.
Short overview of our working flow:


1.Create database and it’s tables.
2.Download php excel library.
3.Write a code which helps to import data into database and also shows the excel data into our webpage.


Here is the way to implement the flow :
We are creating a database named jyotishi and also creating a table ank_jyotishkosh into our database.

we move to our second step and download the PHPExcel library click here to download PHPExcel library .

We are creating a config.php file, which helps to make a connection to our MySQL database.

Now we are creating another PHP file where we write a code for import data into database and shows the data into web page as well.

we are creating a form in bootstrap which takes excel file from user and also add some bootstrap maxcdn files and custom CSS as well.

In the above code you can see a php variable $output at the end of the code, which will use for showing excel data into web page.

Now move to the next step, when user hit on the import button then it checks whether the file is in the excel format or not.


If the file is in excel format then we move further otherwise it will show an error message and requests user to select valid excel file.

If user select valid excel file then we will include our php excel libaray into our code.

We put our data into PHP variable with the help of foreach loop and then shows in a table format and write an insert query which insert our data into database too.

Note : When you run this code and got some error then please make sure you have enabled zip extension on your server.This is the common error which we receive.


If you would like to know how to check whether extension is enabled or not, please check our post on how to enable extension on server.


Keep learning.
Stay connected with us for any queries.

Tags: No tags

Comments are closed.