Jump to content

php post to self form to xml


erilidon

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.