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
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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.