Jump to content

Stuck On Csv To Mysql Code...


techker

Recommended Posts

Hey guys im stuck on this code that keeps on putting " " in my tables?

 

i save the xls file to csv comma delimited.

 

when i upload it ,i get "name" "age"....

 

i think it the '".addslashes($data[0])."',

 

 



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,",","'")); 


 

nice new look by the way.

Link to comment
https://forums.phpfreaks.com/topic/269747-stuck-on-csv-to-mysql-code/
Share on other sites

sorry why do you mean read?i have a form that is used to realy the post..

 


<?php if (!empty($_GET[success])) { echo "<b>CSV Importer!.</b><br><br>"; } //generic success notice ?> 

</p>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1"> 
 Choose your file: <br /> 
 <input name="csv" type="file" id="csv" /> 
 <input name="Year" type="hidden" value="<?=$Fiscale?>" />
 <input type="submit" name="Submit" value="Submit" /> 

</form> 

 

csv looks like this

 

7864804 Abraham Mohamed Masculin 5 ABRM27079607 501

if you specify the correct field delimiters and string terminators then the quotes should disappear.

 

At the moment you are specifying commas when there aren't any and single quote instead of double quote (default) as string terminators.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.