Ciao a tutti,
Forse ci siamo...
Vorrei aggiornare il mio DB tramite l'UPLOAD di un file CSV contenente 52 colonne di dati e circa 6000 righe.
Ecco lo script:
Codice PHP:
<?php 

//connect to the database
$connect mysql_connect("localhost","user","");
mysql_select_db("my_db",$connect); //select the table
//

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 completo (DATO1    ,DATO2    ,DATO3     ,DATO4,    DATO5    ,DATO6    ,DATO7,    DATO8,    DATO9,    DATO10,     DATO11    ,DATO12    ,DATO13,    DATO14,    DATO15,    DATO16     ,DATO17    ,DATO18,    DATO19    ,DATO20,    DATO21,    DATO22,     DATO23,    DATO24,    DATO25,    DATO26,    DATO27,    DATO28,     DATO29,    DATO30,    DATO31    ,DATO32,    DATO33    ,DATO34     ,DATO35    ,DATO36,    DATO37,    DATO38,    DATO39,    DATO40,
DATO41,     DATO42,    DATO43,    DATO44,    DATO45,    DATO46,    DATO47,     DATO48    ,DATO49,    DATO50,    DATO51,    DATO52) 
          
VALUES
                (
                    '"
.addslashes($data[0])."',
                    '"
.addslashes($data[1])."',
                    '"
.addslashes($data[2])."',
                    '"
.addslashes($data[3])."',
                    '"
.addslashes($data[4])."',
                    '"
.addslashes($data[5])."',
                    '"
.addslashes($data[6])."',
                    '"
.addslashes($data[7])."',
                    '"
.addslashes($data[8])."',
                    '"
.addslashes($data[9])."',
                    '"
.addslashes($data[10])."',
                    '"
.addslashes($data[11])."',
                    '"
.addslashes($data[12])."',
                    '"
.addslashes($data[13])."',
                    '"
.addslashes($data[14])."',
                    '"
.addslashes($data[15])."',
                    '"
.addslashes($data[16])."',
                    '"
.addslashes($data[17])."',
                    '"
.addslashes($data[18])."',
                    '"
.addslashes($data[19])."',
                    '"
.addslashes($data[20])."',
                    '"
.addslashes($data[21])."',
                    '"
.addslashes($data[22])."',
                    '"
.addslashes($data[23])."',
                    '"
.addslashes($data[24])."',
                    '"
.addslashes($data[25])."',
                    '"
.addslashes($data[26])."',
                    '"
.addslashes($data[27])."',
                    '"
.addslashes($data[28])."',
                    '"
.addslashes($data[29])."',
                    '"
.addslashes($data[30])."',
                    '"
.addslashes($data[31])."',
                    '"
.addslashes($data[32])."',
                    '"
.addslashes($data[33])."',
                    '"
.addslashes($data[34])."',
                    '"
.addslashes($data[35])."',
                    '"
.addslashes($data[36])."',
                    '"
.addslashes($data[37])."',
                    '"
.addslashes($data[38])."',
                    '"
.addslashes($data[39])."',
                    '"
.addslashes($data[40])."',
                    '"
.addslashes($data[41])."',
                    '"
.addslashes($data[42])."',
                    '"
.addslashes($data[43])."',
                    '"
.addslashes($data[44])."',
                    '"
.addslashes($data[45])."',
                    '"
.addslashes($data[46])."',
                    '"
.addslashes($data[47])."',
                    '"
.addslashes($data[48])."',
                    '"
.addslashes($data[49])."',
                    '"
.addslashes($data[50])."',
                    '"
.addslashes($data[51])."',
                    '"
.addslashes($data[52])."'
                )
            "
);
        }
    } while (
$data fgetcsv($handle,1000,",","'"));
    
//

    //redirect
    
header('Location: import.php?success=1'); die;

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Import a CSV File with PHP & MySQL</title>
</head>

<body>

<?php  if (!empty($_GET[success])) { echo "<b>FILE CARICATO CON  SUCCESSO!</b><br><br>"; } //generic success notice  ?>

<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  Scegli il tuo file: <br />
  <input name="csv" type="file" id="csv" />
  <input type="submit" name="Submit" value="Invia File" />
</form>

</body>
</html>
Il file lo carica con successo ma quando vado ad aprire la mia tabella non vedo nessun dato inserito.
Dove sbaglio?
Potete darmi una mano?