Using xml in stead of mysql for saving registration form info

Greetings experts,
I would like to change a user verification script from php-mysql to php-xml .. I mean I want to store the data and read it from xml in stead of mysql.
To make my question more understandable :-
Lets say that I have a html file that has a form where users enter :
username, password, country, age, telephonenumber, email and will post those info to register.php where we will have the below code :-
(after some php codes to check the entry and make sure every field entered correctly):-

$query="insert into usertable (username, password, country, age, telephonenumber, email) values ('$username', '$password', '$country', '$age', '$telephonenumber', '$email')";
Now the first thing I want to do is to save those variables in an xml file ( lets call it datafile.xml )

The second part of the question is to make a php script to see if the user exists in datafile.xml
In the login form .. the user would enter username and password.
the verification script with mysql would be something like :-
$q="select * from usertable where username like '$username' and password like '$password'";
echo "login successfull";
echo "Invalid username or password";}

I want the script to be able to add as much as user we want from the registration form ( not to replace it every time with one user info ).
Thank you very much in advance.
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lukasz ChmielewskiCommented:
for a beginning I'd recommend the lecture of parsing XML with php
npiut,  that's actually a bad idea.

(1) XML is not very well designed for speed in comparison with a database.  
(2) It's also meant for transmitting data between disparate applications rather than as the data store for an application.
(3) basically, XML-parsing means culling a giant string to figure out which parts belong to what entry.  A DB install takes care of all of this.

npiutAuthor Commented:
Thanks for your comments virmaior .. but i need to change those codes to work on xml and I will use it in a place where i have no database ( can't install ) and the security is not a big issue ( small network with few people accessing it ).
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

a flat csv file would be more efficient than XML and easier to code.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ray PaseurCommented:
I agree with virmaior - a data base is the correct tool, and XML only adds complexity to the issue.  Either install one of the free data bases, or choose the CSV file as your alternative.  

But if you are doing this as a purely academic exercise, you would want to learn about the SimpleXML functions.  They turn an XML file into an object, then you can use iterators like foreach() to walk the object and look for matching usernames, etc.
npiutAuthor Commented:
Ok guys .. here is what I was able to make so far:-
I made the xml file manually ( userinformation.xml ) :-
<?xml version="1.0" encoding="ISO-8859-1"?>


and then I use this php code to check for the user .. to make it easier I simply define the username and password inside the php ( ofcourse it will come from the login form page later ):-
checkuser.php :-
  $doc = new DOMDocument();
  $doc->load( 'userinformation.xml' );
  $books = $doc->getElementsByTagName( "USER" );
  foreach( $books as $book )

  $name = $book->getElementsByTagName( "NAME" );
  $name = $name->item(0)->nodeValue;
  $password = $book->getElementsByTagName( "PASSWORD" );
  $password = $password->item(0)->nodeValue;

  $age = $book->getElementsByTagName( "AGE" );
  $age = $age->item(0)->nodeValue;

  $sex = $book->getElementsByTagName( "SEX" );
  $sex = $sex->item(0)->nodeValue;

  $country = $book->getElementsByTagName( "COUNTRY" );
  $country = $country->item(0)->nodeValue;
if($username==$name && $userpassword==$password){
$completeinfo="Username = $name , Userage = $age , UserSex = $sex , UserCountry = $country ";
if($checkvalue==1){echo "User exists <br> $completeinfo ";}else{echo "User does not exist";}

So basically what I do is I read all the records in the xml file and compare it with the username and password .. if found then I set the variable for checkvalue to 1 .. after reading all the xml file then if the checkvalue = 1 then I display the complete info ( which will become later a welcome screen and a redirection to another page ) .. if username and pw not found then the checkvalue will remain 0 and a message saying ( User does not exist ) will show up and will put the login form to try again.
NOW ! what I need is simply a code to generate the userinformation.xml in stead of creating it manually .. I will make an html page with fields to fill the information and then a registration php page to check the information and make sure they all entered properly .. after passing the check codes I need you guys to write me the code where I can save those info in userinformation.xml.
PLEASE .. NO REDIRECTING TO OTHER TUTORIALS .. I know there is something called ! .. my question is simple me with the codes to write a simple xml file ..
and yes .. all what you said is correct .. using other methodes are much better .. but I need to do it with this simple method.
Thanks again
npiutAuthor Commented:
hopeless website .. it used to be perfect before .. but not anymore.........
Ray PaseurCommented:
@npiut: We do not sit around here waiting for you to give us assignments, you know?  We try to answer questions and offer advice from our experience.  Your question as originally posted sounds like, "I want to use a wrench to drive nails -- instead of a hammer.  Please make me a wrench to pound nails."

In response, virmaior gave you the PERFECT answer: "npiut,  that's actually a bad idea."

Recommend you accept the answer from virmaior.  And I further recommend that you learn about the SimpleXML functions.  Because if you insist on using XML, the choice of DomDocument is almost as wrong for this application as the choice of XML over a database!

As far as the "help me with the codes" part - for that you should hire a developer.  We can offer guidance and sometimes sample code, but we are not paid to write your programming for you - we are volunteers who are trying to help our colleagues in the spirit of the open-source community.

Best of luck with your project, ~Ray
npiutAuthor Commented:
I am out of here .. good luck all
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.