It's usually easier to show with an example : This took about 30 minutes to write :

Here's an XML file - copy and paste, and save as hotels.xml :

<?xml version="1.0"?>
                <name>Bangkok oriental</name>
                <address>50 High Street, Kowloon</address>
                <phone>+12 451 708 3282</phone>
                <name>Hilton Marriott</name>
                <address>2042 Michael Wood Street</address>
                <phone>+44 238 9125467</phone>
                <name>Swallow Royal</name>
                <address>91-97 Royal Fort Crescent</address>
                <phone>+01 1209 432 2345</phone>

At 10:21 19/11/2003 +0000, you wrote:

Hi Neil,

thank you so much for your advice! i have not programmed XML before so it
will take me a while to learn it.. your suggestion sounds really fantastic,
expecially the part when i don't even have to ask the users to direct me to
the file that i need..

my problem, simply put will be:
1) user has to enter details in a form
2) when user enters HotelCode in one of the fields in the  form,
3) javascript must pass the value to PHP to search for the HotelName,
HotelAddress, HotelTel etc..

Forget about PHP if you are doing this client side, you only need it to process the updated records :

>5) javascript place those values in the respective fields
6) user continues to complete the form

Here is a processing page which will populate the form using the XML data : Save this in the same directory you placed the hotels.xml file; It will work in IE5 as is :

        <title>Demo Hotel Loader</title>

<body onload="populatelist()">
<script language="javascript1.2">
oxmlDocument = new ActiveXObject("MSXML2.DOMDocument");

function populatelist() {
        var hotels=oxmlDocument.selectNodes("/hotels/hotel");
        if (hotels != null) {
                d[0]=new Option('--Please Select--','',true);
                for (i=0;i<hotels.length;i++) {
                        d[i+1]=new Option();

function populatevalues() {
// Get hotel ID #
// Use this to read the hotel/phone node having this hotel ID
// Set form's phone field to the text of this node;
// Now to read the hotel/address node having this hotel ID
// Set form's address field to the text of this node

<form name="hotelupdate" id="hotelupdate" action="post" method=""; onsubmit="alert('This would send these values to your website');return false;">
<select name="list" id="list" onchange="populatevalues()"></select> Phone :
<input type="text" name="phone" id="phone" size="15" maxlength="24" />
<br />
<textarea name="address" id="address" rows="3" cols="40" wrap="virtual"></textarea>
<br />
<input type="submit" name="submit" id="submit" value="Send !" />


You then need to write some PHP to accept the new record (you might give the ID number from your database as the primary key). Writing out XML from PHP works exactly the same as writing out HTML. You just fill in the blanks with your data by running a query and printing out the values between the tags, in a loop.

Hope that helps - study the code and see if you can understand how it works.
Cheers - Neil.

PHP Database Mailing List (
To unsubscribe, visit:

Reply via email to