php make copies from xml files



hi im new in xml and php...i trying make an eshop with different xmls for each product..my products shows up corectly with php...i made a fuction with an add buttun and when i pressed it create a copy of each xml with the elements that i need...all products shows well as a list and the button shows in each product as well...but the problem is that each button make a copy of the first xml only(every time) and that i want is to make a copy of the xml where the button located...can someone help?ty


the xmls are 0001.xml



<product gerne="wine"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:noNamespaceSchemaLocation="product.xsd">
<id>0001</id>
<name>krasi</name>
<producer>someone</producer>
<price>12.50</price>
<category>white_wine</category>
<img src="images/white_wine.jpg" width="25" height="80" />

</product


0002.xml



<product gerne="wine"
xmlns:xsi="http://ift.tt/ra1lAU"
xsi:noNamespaceSchemaLocation="product.xsd">
<id>0002</id>
<name>Saint Cosme</name>
<producer>Southern Rhone</producer>
<price>20.40</price>
<category>white_wine</category>
<img src="images/Saintcosme.jpg" width="25" height="80" />

</product>


the php



<?php
$files =glob('*.xml');
foreach($files as $file){
$xml=new SimpleXMLElement($file, 0, true);
if ($xml->category=='white_wine'){

?>
<tr>
<td><p><?php echo $xml->id ?></p></td>
<td><p><?php echo $xml->img->asXML() ?></p></td>

<td><p><?php echo $xml->name ?></p></td>
<td><p><?php echo $xml->producer ?></p></td>
<td><p><?php echo $xml->price ?> &euro; </p></td>

<td><form method="post" action=""><input type="submit" value="Add" name="add" /></form></td>



</tr>



<?php
include 'cProduct_function.php';


} ?>

<?php
}
?>


and the function



<?php




$errors= array();
if((isset($_POST['add']))){

$name =$xml->name;
$producer =$xml->producer;
$id =$xml->id;
$price =$xml->price;
$category =$xml->category;




if(count($errors)== 0){

$xml = new SimpleXMLElement('<product></product>');
$xml->addChild('category', $category);
$xml->addChild('id', $id);
$xml->addChild('name', $name);
$xml->addChild('producer', $producer);
$xml->addChild('price', $price);


$xml->asXML('users/' . $id . '.xml');
header('Location: winerss.php');
die;
}

}
?>

No comments:

Post a Comment