kinglogz
Digital Ethics Advocate
LEVEL 1
300 XP
Submitted by
vishaalmandge
on
Tue, 04/30/2013 - 15:24
Hi friends,
I have following code for import csv file data into mysql, but it won't import the data in database, can any body pls help me for this ?
my code as follows
vishaalmandge
on
Tue, 04/30/2013 - 15:24
Hi friends,
I have following code for import csv file data into mysql, but it won't import the data in database, can any body pls help me for this ?
my code as follows
- <?php
- mysql_connect
(
"localhost"
,
"username"
,
"password"
)
or die
(
mysql_error
(
)
)
;
- mysql_select_db
(
"test"
)
or die
(
mysql_error
(
)
)
;
- if
(
isset
(
$_POST
[
'submit'
]
)
)
- {
- $filename
=
$_POST
[
'filename'
]
;
- $handle
=
fopen
(
"$filename
"
,
"r"
)
;
- while
(
(
$data
=
fgetcsv
(
$handle
,
1000
,
","
)
)
!==
FALSE
)
- {
- $import
=
"INSERT INTO data_status(Date,Campaign_name,Email_id,Mailing_platform,Email_status) values('$data[0]
','$data[1]
','$data[2]
','$data[3]
','$data[4]
')"
;
- mysql_query
(
$import
)
or die
(
mysql_error
(
)
)
;
- }
- fclose
(
$handle
)
;
- print
"Import done"
;
- }
- else
- {
- print
"There is nothing to do, click here to go back home"
;
- }
- ?>