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.
The HTTP server normally runs with an user without permission to modify files on the server. Most web applications store any data which can be modified in a database.
If you want to have a file or directory writable by the web server, you can try:
And after that you can write to the file from your original php file.
I guess you get a 500 error if either your php script or its parent directory is world writable. Depending on your hosting provider, it may work if you create a separate directory for any files written to by the server.