I do not know how to resolve this error Undefined variable: _DATOS_EXCEL in C: \ xampp \ htdocs \ kidv2 \ index.php on line 70

0
for ($i=2;$i<=$filas;$i++){
                    //$_DATOS_EXCEL[$i]['id'] = 1;

                    $_DATOS_EXCEL[$i]['nombre'] = $objPHPExcel->getActiveSheet()->getCell('A'.$i)->getCalculatedValue();
                    $_DATOS_EXCEL[$i]['fechainicio'] = $objPHPExcel->getActiveSheet()->getCell('B'.$i)->getCalculatedValue();
                    $_DATOS_EXCEL[$i]['horainicio']= $objPHPExcel->getActiveSheet()->getCell('C'.$i)->getCalculatedValue();
                    $_DATOS_EXCEL[$i]['fechafinal']= $objPHPExcel->getActiveSheet()->getCell('D'.$i)->getCalculatedValue();
                    $_DATOS_EXCEL[$i]['horafinal'] = $objPHPExcel->getActiveSheet()->getCell('E'.$i)->getCalculatedValue();

                }       
                $errores=0;


foreach($_DATOS_EXCEL as $campo => $valor){
     $sql = "INSERT INTO registro(id,nombre,fechainicio,horainicio,fechafinal,horafinal)  VALUES ('";
                    foreach ($valor as $campo2 => $valor2){
                        $campo2 == "activo" ? $sql.= $valor2."');" : $sql.= $valor2."','";
                    }

                    $result = mysqli_query($sql);
                    if (!$result){ echo "Error al insertar registro ".$campo;$errores+=1;}
                }   
    
asked by Oscar Armando Poblano Paz 25.06.2018 в 19:46
source

2 answers

0

If the variable $_DATOS_EXCEL was not initialized before using it, try to initialize it as an array or as a multiple array. $_DATOS_EXEL = array()

    
answered by 25.06.2018 в 20:06
0

You must start the variable before the loop so that it is accessible outside of it, regardless of whether you contribute content in for .

$_DATOS_EXCEL = array();

for($i=2.....
    
answered by 25.06.2018 в 20:54