Hi i'm trying to put together a simple registration page for a school assignment,
but am having alot of trouble trying to figure out the dom library,
at the moment my code looks something like this,
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$fName = $_POST['fName'];
$dob = $_POST['dob'];
$program = $_POST['program'];
$programExpires = $_POST['programExpires'];
$sNumber = $_POST['sNumber'];
$email = $_POST['email'];
$address = $_POST['address'];
$phoneNo = $_POST['phoneNo'];
$msg="";
$flag=0;
//all my validation code goes here
//
//open a xml document for writing
$doc = new DOMDocument();
$doc->load( 'users.xml' );
$user = $doc->getElementsByTagName( "user" );
$element1 = $user->createElement( "username" );
$user->appendChild( $element1 );
$element2 = $user->createElement( "password" );
$user->appendChild( "$element2" );
$element3 = $user->createElement( "firstname" );
$user->appendChild( "$element3" );
$doc->saveXML();
?>
i've just started trying to get the writing to xml to work, but keep getting stuck 🙁
I find heaps of examples on the internet that will create a new DOM document from scratch,
but i want to just add a new user to my current xml document.
which is layed out like this:
<?xml version="1.0"?>
<users>
<user>
<username>test</username>
<password>password</password>
<firstName>name1</firstName>
<dateOfBirth>10/10/1990</dateOfBirth>
</user>
<user>
<username>test2</username>
<password>password</password>
<firstName>name2</firstName>
<dateOfBirth>10/10/1991</dateOfBirth>
</user>
</users>
If anyone could give me an example of creating a new user in my xml to set me
on the right path I would really appreciate it!
any help would be great!
thanks
Tim