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.
This code should give you what you need. You will need to adjust it in a few places, to fit what you already have.