473,387 Members | 1,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

How to import excel data into mysql using php?

26
Hi,

i tiring to insert excel data into mysql using php.

1. i saved the Excel data as a CSV file.
2. i use below code to retrieve data.
Expand|Select|Wrap|Line Numbers
  1. $fcontents = file('./ite_APS.csv');
  2. for($i=0;$i<sizeof($fcontents);$i++)
  3. {
  4.     $line = trim($fcontents[$i]);
  5.     $arr = explode(",",$line);
  6.     $sql = implode("','",$arr);
  7.     echo "$sql <br>";
  8. }
  9.  
i got is output, but i don't know how to insert the data in mysql. can you help me?
Expand|Select|Wrap|Line Numbers
  1. EMPLID','COMPLETE_NAME','STRM','SESSION_CODE','SUBJECT','CATALOG_NBR','COURSE_TITLE_LONG','CRSE_GRADE_OFF','UNT_EARNED','CUM_GPA 
  2. F1809289K','JEGANNES A/L C KRISHNAN','5081','E05','EM','20000','Communication Skills','U','2','0.75 
  3. F1809289K','JEGANNES A/L C KRISHNAN','5081','E05','EM','20070','Information Technology','U','1','0.75 
  4. F1809289K','JEGANNES A/L C KRISHNAN','5081','E05','ME','28020','Piping & Valve System','F','6','0.75 
  5. F1809289K','JEGANNES A/L C KRISHNAN','5081','E05','ME','28050','Mechanical Fabrication','F','6','0.75 
  6. F1809289K','JEGANNES A/L C KRISHNAN','5087','E11','EM','20030','Personal Effectiveness','U','3','0.75 
  7. F1809289K','JEGANNES A/L C KRISHNAN','5087','E11','EM','20060','Sports & Wellness I','U','1','0.75 
  8. G0428701R','WEI HUAJIE ','5091','E05','EE','28110','Fundamentals of Electricity','C','6','2.25 
  9. G0428701R','WEI HUAJIE ','5091','E05','EE','28120','Residential Wiring Systems','C','6','2.25 
  10. G0428701R','WEI HUAJIE ','5091','E05','EE','29060','Basic Electronics','B','2','2.25 
  11. G0428701R','WEI HUAJIE ','5091','E05','EM','20000','Communication Skills','S','2','2.25 
  12. G0428701R','WEI HUAJIE ','5091','E05','EM','20070','Information Technology','S','1','2.25 
  13. G0428701R','WEI HUAJIE ','5097','E11','EE','28130','Industrial Wiring Systems','B','6','2.25 
  14. G0428701R','WEI HUAJIE ','5097','E11','EE','28140','Electrical Maintenance and Control','C','6','2.25 
  15.  
Mar 7 '11 #1
4 4411
Hello,

You have to write some php code like below

Expand|Select|Wrap|Line Numbers
  1. mysql_connect('your host','your username','your password');
  2.  
  3. mysql_select_db('your database name');
  4.  
  5. $insquery = "INSERT INTO `tbl_name` (`field1`, `field2`, `field3`) VALUES ('val1', 'val2', 'val3'), ('val1', 'val2', 'val3');";
  6. mysql_query($insquery);
  7.  
Regards,
Mayur Bhayani
Mar 7 '11 #2
apssiva
26
thanks,

but i have one doubt, one user have multiple "COURSE_TITLE" how i can insert? pls check my above output...
Mar 7 '11 #3
Hello,

For that you have to set user_id in your mysql table.

Regards,
Mayur Bhayani
Mar 7 '11 #4
apssiva
26
All data are in excel sheet. the table is empty now. i will insert this excel data in to the table. pls any one help.........
Mar 7 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rathtap | last post by:
I want to set up the import of data from an excel file into SQL Server from my ASP.net (C#) application. The user will select the file that needs importing. I want to use DTS to do this. I was...
10
by: Niklas | last post by:
Hi Before I start coding I need to be sure that nobody else has not done it yet and that I can use it. I need an import utility which import data from Excel to a database or some object in...
1
by: chirag thakor | last post by:
how i can import data from Excel to MySql using php.
0
by: levis123 | last post by:
hi, anybody know how to import excel data into sql server using asp.net (vb.net). i've read some articles in the internet, however, try to implement it seems...still have problems...any1 who solved...
0
by: ghazal01978 | last post by:
hi all I need some help how to import excel data into sql server using vb6? I have a sub , and used that but for many fieldes had problem , although those fields had text format data , vb...
9
sukumar 123
by: sukumar 123 | last post by:
need to import Excel data into Mysql database using coldfusion script. How can i do it. Is there any utility or any script can do it. Thanks in advance.
4
by: meeanji | last post by:
php codes goes like this<? $fcontents = file ('./spreadsheet.xls'); # expects the csv file to be in the same dir as this script for($i=0; $i<sizeof($fcontents); $i++) { $line =...
0
by: prashantdixit | last post by:
Hi, I have beent trying importing Excel data with one column containing PDF/JPEG file name to access 2007. I have a Excel file with few columns One of the columns named as "Reference". The...
4
by: colintis | last post by:
Before asking the question I've been digging a hole that is deep enough to bury myself in google....Most of the results are simply importing the excel file to table with the same table structure. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.