Content not updating in xml file on hosting server.
<?php
$xml = new DOMDocument('1.0', 'utf-8');
$xml->formatOutput = true;
$xml->preserveWhiteSpace = false;
$xml->load('rates.xml');
//Get item Element
$element = $xml->getElementsByTagName('rates')->item(0);
//Load child elements
$name = $element->getElementsByTagName('gold')->item(0);
$comment = $element->getElementsByTagName('silver')->item(0);
//Replace old elements with new
$element->replaceChild($name, $name);
$element->replaceChild($comment, $comment);
?>
<body><hr>
<form method="POST" action='' autocomplete="off">
Enter Gold Rate (Rs/10g) : <input required type="text" value="<?php echo $name->nodeValue ?>" name="gold-rate" pattern="^[0-9]{5}$" placeholder="for 10g"></br></br>
Enter Silver Rate (Rs/kg) : <input required type="text" value="<?php echo $comment->nodeValue ?>" name="silver-rate" pattern="^[0-9]{5}$" placeholder="for 10g"/></br></br>
<input name="submit" type="submit" />
</form><hr>
</body>
<?php
if (isset($_POST['submit']))
{
$name->nodeValue = $_POST['gold-rate'];
$comment->nodeValue = $_POST['silver-rate'];
htmlentities($xml->save('sample.xml'));
}
?>
Above code is about form submission of two values i am trying to save in XML and then display it elsewhere. On local-host it got success, but on server this php script is unable to change the data of my XML file. Permissions for the folder i set is 755 and all files at 644. Tried changing the permissions and ended up with 500 internal error. As this looks server-side security matter, i have no clue where to end up looking for solution. Server is running on PHP 5.6, tried solutions from other users but nothing fruitful. Should i have to change something in php or do i have to contact my hosting provider.