I write a small program that is supposed to update an xml file (KPI.xml) with an html form. I compared my code with everything I found o internet and haven't been able to find why my xml doc doesn't change when I complete the form. PHP doesn't return me any error.
Here is my code:
<form method='post'action=''>
<label>Mois</label>
<input type='text' name='mois'/>
<br>
<label>Jour</label>
<input type='text' name='jour'/>
<br>
<label>RNC</label>
<input type='text' name='rnc'/>
<br>
<label>Production</label>
<input type='text' name='production'/>
<br>
<label>DROP</label>
<input type='text' name='DROP'/>
<br>
<input type='submit' value='submit'/>
</form>
<?php
if (isset($_POST['submit'])) {
$xmldoc = new DOMDocument('1.0');
$xmldoc ->load("KPI.xml");
$mois = $_POST['mois'];
$Jour = $_POST['jour'];
$rnc = $_POST['rnc'];
$Prod = $_POST['production'];
$DROP = $_POST['DROP'];
// find the headercontent tag
//$root = $xmldoc->getElementsByTagName('Usine')->item(0);
// create the <product> tag
$KPI = $xmldoc->createElement('KPI');
$KPI ->setAttribute('mois', $mois);
// create other elements and add it to the <KPI> tag.
$jourElement = $xmldoc->createElement('Jour');
$jourText = $xmldoc->createTextNode($Jour);
$KPI->appendChild($jourElement);
$jourElement->appendChild($jourText);
$rncElement = $xmldoc->createElement('RNC');
$rncText = $xmldoc->createTextNode($rnc);
$KPI->appendChild($rncElement);
$rncElement->appendChild($rncText);
$DROPElement = $xmldoc->createElement('DROP');
$DROPText = $xmldoc->createTextNode($DROP);
$KPI->appendChild($DROPElement);
$DROPElement->appendChild($DROPText);
$ProdElement = $xmldoc->createElement('Prod');
$ProdText = $xmldoc->createTextNode($Prod);
$KPI->appendChild($ProdElement);
$ProdElement->appendChild($ProdText);
// add KPI to the DOM
$xmldoc->documentElement->appendChild($KPI);
$xmldoc->save("KPI.xml");
}
?>
 
No comments:
Post a Comment