I have an XML file that I want to be able to edit using a form.
student.xml
<students>
<student>
<name>Jane Doe</name>
<email>email@email.com</email>
<school>School Name</school>
<coach>Coach Name</coach>
</student>
</students>
Basically my form is set up like this:
<form method="post">
<input name="name" id="name" type="text">
<input name="school" id="school" type="text">
<input name="coach" id="coach" type="text">
<br>
<input type="submit" name="submit" value="submit">
</form>
PHP code:
<?php
if(isset($_POST['submit'])) {
$data=simplexml_load_file('student.xml');
$data->student->name=$_POST['name'];
$data->student->school=$_POST['school'];
$data->student->coach=$_POST['coach'];
$handle=fopen("student.xml","wb");
fwrite($handle,$data->asXML());
fclose($handle);
}
$data=simplexml_load_file('student.xml');
?>
How can I use a form to edit multiple nodes in one form? Right now it changes all the nodes to the same as the first one.
Edit: Code is updated. It all seems to be working now. Thanks for the help.