Why is this PHP giving error in writing an XML?

3

I'm trying to make a simple XML that takes the data registered in a page in PHP but is giving error, can someone tell me what it is and how it can work?

Error that appears when you press the button:

  

Fatal error: Uncaught exception 'DOMException' with message 'Hierarchy Request Error' in C: \ xampp ... \ cadastro.php: 17 Stack trace: # 0 C: \ xampp ... \ cadastro.php (17 ): DOMNode-> appendChild (Object (DOMElement)) # 1 {main} thrown in C: \ xampp ... \ cadastro.php on line 17

Entire page code:

<?php 

if (isset($_POST['insert'])){

$xml= new DOMDocument("1.0", "UTF-8");
$xml->load('studentdb.xml');

$nome = $_POST['nome'];
$endereco = $_POST['endereco'];

$rootTag = $xml->getElementsByTagName("roo")->item(0);

$infoTag = $xml->createElement("info");
    $nomeTag = $xml->createElement("nome", $nome);
    $enderecoTag = $xml->createElement("endereco", $endereco);

    $nomeTag->appendChild($nomeTag);
    $enderecoTag->appendChild($enderecoTag);

$rootTag->appendChild($infoTag);
$xml->save('studentdb.xml');

}
?>

<html>
<body>
<form method="post" action="cadastro.php">
Informacoes <br>
Nome <input type="text" name="nome"> <br>
Endereco <input type="text" name="endereco"> <br>
<input type="submit" name="insert" value="add">
</form>
</body>
</html>
    
asked by anonymous 22.11.2015 / 23:33

1 answer

0

This error is because you are trying to move a node within itself.

Here , an explanation of a question just like yours.

I hope I have helped.

UPDATING:

Take a look at lines 17 and 18 of your code. I think that's the problem.

$nomeTag->appendChild($nomeTag);
$enderecoTag->appendChild($enderecoTag);
    
22.11.2015 / 23:38