sql - Undefined variable data when I try to import a csv file in php -
im trying import csv file in sql database using php.
i have code
<?php echo $_files['userfile']['name']; echo $_files['userfile']['size']; include ("accesobd.php"); if ($_files['userfile']['size'] > 0) { echo "el archivo contiene informacion"; $file = $_files['userfile']['tmp_name']; $handle = fopen($file,"r"); $data2 = fgetcsv($handle,1000,",","'"); { if ($data[0]) { echo "entramos en el import"; mysql_query("insert alumno (nombre, apellidos, correoelectronico) values ( '".addslashes($data[0])."', '".addslashes($data[1])."', '".addslashes($data[2])."' ) "); } } while ($data = fgetcsv($handle,1000,",","'")); } ?>
i file information correctly, , accesobd it´s class manage conexion database, error data variable not declared.
the point loop enters correct number of times should , prints correct number of times echo "entramos en el import", inserts nothing find no such variable data.
the literal error gives me browser is
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
pd sorry if have bad english, it´s first time trying make formal question using language :)
you defined $data2 , use $data undefined.
$data2 = fgetcsv($handle,1000,",","'"); { if ($data[0]) {
Comments
Post a Comment