Jump to content

Help with DOM putting post data into a xml.


timmeh1

Recommended Posts

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
//script to register new users.
//import validation methods
include_once 'validation.php';
//COLLECTING FORM DATA IN GLOBAL VARIABLES FROM REGISTER.HTML
$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>

 

 

any help would be great!

thanks

Tim

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.