hola
necesito ayuda soy nuevo en php y necesito insertar datos de un xml a una base de datos mysql he formado un script pero me retorna este warning q imagino q sea algún problema en la sintaxis. ak les dejo el .php gracias.
/<?php
// fichero a importar
$xml_file = 'nbreport.xml';
$i = 0;
if (file_exists($xml_file)) { $xml = simplexml_load_file($xml_file);
} else {
exit('Error al intentar abrir el fichero '.$xml_file);
}
// sacamos las variables del XML
linea 19 $hora = $xml -> {'variable-set'} -> attributes()-> timestamp ;
$nombre = $xml -> {'variable-set'} -> variable[0] -> metadata[3] -> {'nls-string-val'} ;
linea 21 foreach ($xml -> {'variable-set'} -> variable as $var) {
switch((string) $var['varid']) { // Toma los atributos como índices del elemento
case 'nbEyeEnc_0_CMOT':
$camara= ( $xml -> {'variable-set'} -> variable[$i] -> {'u32-val'});
$i++;
break;
case 'nbEyeEnc_0_DOOR':
$puerta= ( $xml -> {'variable-set'} -> variable[$i] -> {'u32-val'});
$i++;
break;
case 'nbHawkEnc_0_DEW':
$rocio= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
case 'nbHawkEnc_0_AUDI':
$audio= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
case 'nbHawkEnc_0_AFLW':
$aire= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
case 'nbHawkEnc_0_HUMI':
$hum1= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
case 'nbHawkEnc_0_HUMI2':
$hum2= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
case 'nbHawkEnc_0_TEMP':
$temp1= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
case 'nbHawkEnc_0_TEMP3':
$temp2= ( $xml -> {'variable-set'} -> variable[$i] -> {'double-val'});
$i++;
break;
default:
$i++;
}
}
// abrimos la BD
require 'config.php';
// Insertamos los datos en la BD
mysql_query ( "INSERT INTO nbreport (time, nombre, camara, door, ptorocio, audio, aire, humint, humext, tempint, tempext) VALUES ('$hora', '$nombre', '$camara', '$puerta', '$rocio', '$audio', '$$aire', '$hum1', '$hum2', '$tem1', '$temp2')")
or die(mysql_error());
?>
el resultado es
/
Warning: main(): Node no longer exists in C:\xampp\htdocs\php\importmysql\import
-xml.php on line 19
Warning: main(): Node no longer exists in C:\xampp\htdocs\php\importmysql\import
-xml.php on line 19
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\php\importmy
sql\import-xml.php on line 22