tags:

views:

78

answers:

1

Hello, I wrote this code to quickly edit an existing XML file and save changes to the file. However, it doesn't seem to be writing my data to the xml file. Am I using asXML() wrong? Thanks for your help.

<?php

 $xml = simplexml_load_file("../xml/emp.xml");


 $xml->employee[0]['empID'] = $_POST['empID'];

 $xml->employee[0]->empFN = $_POST['first'];

 $xml->employee[0]->empLN = $_POST['last'];

 $xml->employee[0]->empDept['number'] = $_POST['num'];

 $xml->employee[0]->empDept->empSup = $_POST['supv'];

 $xml->employee[0]->emp_ext = $_POST['ext'];

 $xml->employee[0]->k_plan = $_POST['plan'];


 $xml->asXML();

 header('Location: confirm_form.php');

?>
A: 

If you want to use asXML() to write to a file then you have to specify the filename, as instructed in the manual.

$xml->asXML("../xml/emp.xml");
Josh Davis
Thanks I've edited that, but the XML is still not being written to the file.
ScroLL
Ugh, problem solved. I changed a line to this: file_put_contents("../xml/emp.xml", $xml->asXML());but what really solved the problem was setting the file to write permissions on my server. ALWAYS REMEMBER TO SET YOUR FILE PERMISSIONS
ScroLL
Using file_put_contents() rather than asXML() is stupid but sure, go ahead and do that. Also, I heard that not hiding PHP errors was kind of useful during development.
Josh Davis