erilidon Posted February 5, 2012 Share Posted February 5, 2012 why doesn't this work? <form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="text" id="name" name="name" size="20" /></p> <input type="submit" name="submit" value="Submit" alt="Submit" /> </form> <? if($name != "") { $xml = simplexml_load_file("invoice.xml"); $sxe = new SimpleXMLElement($xml->asXML()); $itemsNode = $sxe->data[0]; $main = $itemsNode->addChild(inv); $sub = $main->addChild("name", $name); $sxe->asXML("invoice.xml"); } ?> The existing xml file looks like this: <?xml version="1.0" encoding="utf-8"?> <root> <data> <inv> <name>Sally Prince</name> </inv> </data> </root> And, my intention is is I fill out the form with "Bill Gates" the xml will become: <?xml version="1.0" encoding="utf-8"?> <root> <data> <inv> <name>Sally Prince</name> </inv> <inv> <name>Bill Gates</name> </inv> </data> </root> Also if I just set $name = "Bill Gates" it works.. but the form will not pass the data to the xml.. what am I missing? Thanks! Link to comment https://forums.phpfreaks.com/topic/256424-php-post-to-self-form-to-xml/ Share on other sites More sharing options...
digibucc Posted February 5, 2012 Share Posted February 5, 2012 $name is an undefined vairable. try $_POST['name']; Link to comment https://forums.phpfreaks.com/topic/256424-php-post-to-self-form-to-xml/#findComment-1314609 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.