Where am i wrong here? Error using XML with PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
helioslive
Forum Newbie
Posts: 4
Joined: Tue Jan 06, 2009 5:35 pm
Location: Coding somewhere

Where am i wrong here? Error using XML with PHP?

Post by helioslive »

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)

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;
?>
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!
User avatar
helioslive
Forum Newbie
Posts: 4
Joined: Tue Jan 06, 2009 5:35 pm
Location: Coding somewhere

Re: Where am i wrong here? Error using XML with PHP?

Post by helioslive »

Anyone? :?:
Post Reply