I am placing attributes inside an XML element based on user input on a form. The try is throwing a Hierarchy Request Error. I don't see the error. Am I doing this incorrect? I am not a daily programmer.
<html>
<head>
<title></title>
</head>
<body>
<?php
if (isset($_REQUEST['ok'])) {
try {
$xml = new DOMDocument("1.0", "UTF-8");
$xml->load("PhoneBook.xml");
$xmlYealink = $xml->getElementsByTagName("YealinkIPPhoneBook")->item(0);
$xml_Menu = $xml->createElement("Menu");
$xml_Menu->setAttribute("Name", "Drivers");
$xml_Unit = $xml->createElement("Unit");
$xml_Unit->setAttribute("Name", $_REQUEST['name']);
$xml_Unit->setAttribute("Phone3", $_REQUEST['phone3']);
$xml_Unit->setAttribute("Phone2", $_REQUEST['phone2']);
$xml_Unit->setAttribute("Phone1", $_REQUEST['phone1']);
$xml_Unit->appendChild($xml_Unit);
$xml_Menu->appendChild($xml_Menu);
$xml->save("PhoneBook.xml");
} catch (Exception $e) {
echo $e->getMessage();
}
}
?>
<form method="post">
<label for="name">Name</label> <input type="text" name="name" /> </br>
<label for="phone3">Extension</label> <input type="text" name="phone3" /> </br>
<label for="phone2">Direct</label> <input type="text"name="phone2" /> </br>
<label for="phone1">Cellular</label> <input type="text" name="phone1" /> </br>
<input type="submit" name="ok" value="Submit Entry">
</form>
</body>
</html>