• We just launched and are currently in beta. Join us as we build and grow the community.

Import CSV file into mysql using php

kinglogz

Digital Ethics Advocate
K Rep
0
0
0
Rep
0
K Vouches
0
0
0
Vouches
0
Posts
78
Likes
75
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
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
  1. <?php

  2. mysql_connect

    (

    "localhost"

    ,

    "username"

    ,

    "password"

    )

    or die

    (

    mysql_error

    (

    )

    )

    ;

  3. mysql_select_db

    (

    "test"

    )

    or die

    (

    mysql_error

    (

    )

    )

    ;


  4. if

    (

    isset

    (

    $_POST

    [

    'submit'

    ]

    )

    )
  5. {
  6. $filename

    =

    $_POST

    [

    'filename'

    ]

    ;
  7. $handle

    =

    fopen

    (

    "$filename

    "

    ,

    "r"

    )

    ;
  8. while

    (

    (

    $data

    =

    fgetcsv

    (

    $handle

    ,

    1000

    ,

    ","

    )

    )

    !==

    FALSE

    )
  9. {

  10. $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]

    ')"

    ;
  11. mysql_query

    (

    $import

    )

    or die

    (

    mysql_error

    (

    )

    )

    ;
  12. }
  13. fclose

    (

    $handle

    )

    ;
  14. print

    "Import done"

    ;

  15. }
  16. else
  17. {

  18. print

    "There is nothing to do, click here to go back home"

    ;

  19. }

  20. ?>

 

440,010

316,559

316,568

Top