Where am i wrong here? Error using XML with PHP?
Posted: Thu Jan 08, 2009 10:02 am
Well, i'm doing a little script to change the atribute of an XML document. This little script is supposed to be called from a normal HTML webpage, only to change the atribute. You are able to specify by the "$_GET" function the element, the element number, and the value which you would like to change in the XML document.
Here it is my actual code:
(let's say i call this by: bla.php?&etiq=idontknow&elem=0&valor=hello)
EDIT: The output for this is:
Warning: main() [function.main]: Cannot write or create unnamed element in C:\AppServ\www\try.php on line 10
Where is my error? And if you know a better way to do it... share it please!
Thanks!
Here it is my actual code:
(let's say i call this by: bla.php?&etiq=idontknow&elem=0&valor=hello)
Code: Select all
<?php
if (file_exists('1.xml')) {
$xml = simplexml_load_file('1.xml');
} else {
exit('Error al abrir Base de Datos XML, consulte a su agente de ventas.');
}
$x = $_GET['etiq'];
$y = $_GET['elem'];
$z = $_GET['valor'];
$xml->${$etiq}[$elem] = $valor;
echo $xml->asXML();
$xml->saveXML('2.xml'); // save as file;
?>Warning: main() [function.main]: Cannot write or create unnamed element in C:\AppServ\www\try.php on line 10
Where is my error? And if you know a better way to do it... share it please!
Thanks!