#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2005
    Posts
    641
    Rep Power
    17

    Import CSV file but gives ""


    Hey guys i have a CSV uploader but i don't know what format i should save the xls to CSV ..cause i tryed comma delimited..

    when i import to mysql i get "name" ...

    what CSV format should i use?

    uploader

    PHP Code:
    if ($_FILES[csv][size] > 0) { 

        
    //get the csv file 
        
    $file $_FILES[csv][tmp_name]; 
        
    $handle fopen($file,"r"); 
         
        
    //loop through the csv file and insert into database 
        
    do { 
            if (
    $data[0]) { 
                
    mysql_query("INSERT INTO  $Year (Ecole,N_Fiche,Nom,Prenom,Code_P,Foyer,Secondaire,Annee,Sortie) VALUES 
                    ( 
                        '263',
                        '"
    .addslashes($data[0])."',
                        '"
    .addslashes($data[1])."', 
                        '"
    .addslashes($data[2])."',
                        '"
    .addslashes($data[5])."',
                        '"
    .addslashes($data[6])."',
                        '"
    .addslashes($data[4])."',
                        '
    $Year',
                        '"
    .addslashes($data[7])."' 
                    ) 
                "
    ); 
            } 
        } while (
    $data fgetcsv($handle,1000,",","'")); 
        
    // 

        //redirect 
        
    echo "<meta http-equiv=Refresh content=1;url=Admin.php?success=1>";die; 




  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,466
    Rep Power
    1751
    Any reason you don't use the LOAD DATA option?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Oct 2005
    Posts
    641
    Rep Power
    17
    the code works just as good..LOAD data will do what more?

    think its the ".addslashes($data[0])." that adds the """

IMN logo majestic logo threadwatch logo seochat tools logo