Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7505187
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T21:49:17+00:00 2026-05-29T21:49:17+00:00

I am trying to auto increment my xml file. I have a form that

  • 0

I am trying to auto increment my xml file. I have a form that people submit and save information into a xml doc. I can’t get to auto increment. The data is save but the id stay the same which is 0

XML document schema

<affiliates>

    <affiliate id="0">
        <FullName></FullName>
        <Company></Company>
        <Degree_Certificate></Degree_Certificate>
        <City></City>
        <StateProvidenceRegion></StateProvidenceRegion>
        <Phone></Phone>
        <Emailaddress></Emailaddress>
        <Descriptions></Descriptions>
    </affiliate>

<affiliates>

PHP code: problems:

$root = $doc->createElement('affiliate', '');
$aff = count($root);
for ($i = 0; $i < $aff; $i++)
{
    $root->setAttribute('id', $i);
    $fullname = $doc->createElement('FullName', $fname.' '.$lname);
    $certdegree = $doc->createElement('Degree_Certificate', $degree);
    $Company = $doc->createElement('Company', $company);
    $Street = $doc->createElement('City', $address);
    $StateProvidenceRegion = $doc->createElement('StateProvidenceRegion', $state);
    $Phone = $doc->createElement('Phone', $phone);
    $EmailAddress = $doc->createElement('Emailaddress', $email);
    $Description = $doc->createElement('Descriptions', $message);
    $doc->appendChild($root);
    $root->appendChild($fullname);
    $root->appendChild($Company);
    $root->appendChild($certdegree);
    $root->appendChild($Street);
    $root->appendChild($StateProvidenceRegion);
    $root->appendChild($Phone);
    $root->appendChild($EmailAddress);
    $root->appendChild($Description);
    $doc->documentElement->appendChild($root);
}

Help me please with this code. PHP is not my strong point. What piece of code did I not add.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T21:49:18+00:00Added an answer on May 29, 2026 at 9:49 pm
    <?php
    //Process form data here.
    
    //Get the XML Document
    $doc = new DOMDocument();
    $doc->load("affiliates.xml"); //Load the existing XML here.
    
    //Get the affiliates node here
    $root = $doc->documentElement;
    
    //Get the ID of this record here.
    //If you know that no affiliate entries will ever be deleted, then you can use the total number of entries as the next increment value.
    $totalAffiliates = $root->childNodes->length;
    
    $node = $doc->createElement("affiliate");
    $node->setAttribute("id", $totalAffiliates);
    $node->appendChild($doc->createElement("FullName", $fname . ' ' . $lname));
    $node->appendChild($doc->createElement("Degree_Certificate", $degree));
    $node->appendChild($doc->createElement("Company", $company));
    $node->appendChild($doc->createElement("City", $address));
    $node->appendChild($doc->createElement("StateProvidenceRegion", $state));
    $node->appendChild($doc->createElement("Phone", $phone));
    $node->appendChild($doc->createElement("Emailaddress", $email));
    $node->appendChild($doc->createElement("Descriptions", $message));
    
    $root->appendChild($node);
    
    //Write your XML back to the file.
    ?>
    

    This code should give you what you need. You will need to adjust it in a few places, to fit what you already have.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file containing seed data that I'm trying to load into
I have a db table that has the following structure: id (auto increment), title
I have a MySQL table with an auto-increment field and I am trying to
I have realised that mnesia doesnot support auto-increment feature as does MySQL or other
im trying to getting auto complete working and i can do so fine when
I was trying to write code that would auto-close a Toplevel Tk window in
I am just trying to get the auto incremented value of a table that
I have a Customer table with a Primary key (int auto increment) and an
I'm trying to create a table that has a primary key (Department_ID) that auto
I'm trying to set up a model using UUIDs instead of auto-increment. Without bothering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.