title: Undefined variable data when I try to import a csv file in php
body: <p>Im trying to import a CSV file in my SQL Database using PHP.</p>
  
  <p>I have this code</p>
  
  <pre><code>&lt;?php  
  
      echo $_FILES['userfile']['name'];
  
      echo $_FILES['userfile']['size'];
  
      include ("AccesoBD.php");
  
      if ($_FILES['userfile']['size'] &gt; 0) {
          echo "El archivo contiene informacion";
  
          $file = $_FILES['userfile']['tmp_name']; 
          $handle = fopen($file,"r"); 
          $data2 = fgetcsv($handle,1000,",","'");
  
          do { 
          if ($data[0]) { 
              echo "Entramos en el Import";
              mysql_query("INSERT INTO Alumno (Nombre, Apellidos, CorreoElectronico) VALUES 
                  ( 
                      '".addslashes($data[0])."', 
                      '".addslashes($data[1])."', 
                      '".addslashes($data[2])."' 
                  ) 
              "); 
          } 
          } while ($data = fgetcsv($handle,1000,",","'")); 
  
  
      }
  
  
  ?&gt; 
  </code></pre>
  
  <p>I get the file information correctly, and AccesoBD it´s an extra class to manage my conexion to the database, but I get the error that data variable is not declared. </p>
  
  <p>The point is that the loop enters the correct number of times as it should do and prints the correct number of times the echo "Entramos en el Import", but then inserts nothing to find no such variable data.</p>
  
  <p>The literal error that gives me the browser is</p>
  
  <pre><code>alumnos.csv80El archivo contiene informacion
  Notice: Undefined variable: data in C:\xampp\htdocs\iprofesor\importaralumnoss.php on line 17
  Entramos en el ImportEntramos en el Import
  </code></pre>
  
  <p>PD Sorry if i have a bad english, it´s my first time trying to make a formal question using the language :)</p>