everybody! My problem is as follows: I am using an xml file with products info. Here it is - example.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<products>
<item>
<name>Flat Screen Television SONY KDL-4500WEED</name>
<image>http://img.zap.co.il/pics/2/7/9/2/37682972c.gif</image>
<description>This is our newest TV set from the SONY Comp. and we hope you buy it mothefuckerzzzz....zasdhaskjdhkahdca a dsah dha adlasldoao al ladjjada</description>
<left>17</left>
</item>
<item>
<name>Aiwa ozvuchitelna sistema</name>
<image>http://crev.vo.llnwd.net/o42/audioreview/images/products/product_119021.jpg</image>
<description>This is our newest TV set from the Aiwa Comp. and we hope you buy it mothefuckerzzzz....zasdhaskjdhkahdca a dsah dha adlasldoao al ladjjada</description>
<left>12</left>
</item>
<item>
<name>Blu-Ray DVD Player Panasonic</name>
<image>http://news.cnet.com/i/bto/20070725/BD-UP5000_overhead.jpg</image>
<description>This is our newest TV set from the Aiwa Comp. and we hope you buy it mothefuckerzzzz....zasdhaskjdhkahdca a dsah dha adlasldoao al ladjjada</description>
<left>33</left>
</item>
<item>
<name>DURO na SHISH...</name>
<image>http://media.otkrovenia.com/profiles/DureFF.jpg</image>
<description>This is our newest TV set from the Aiwa Comp. and we hope you buy it mothefuckerzzzz....zasdhaskjdhkahdca a dsah dha adlasldoao al ladjjada</description>
<left>18</left>
</item>
</products>
The idea is that a User can reserve numbers of the products by a php page, which will automatically tell him how many are left and change the values of the xml file of the certain products. Here is my php page - metro.php:
<?php
$products = simplexml_load_file("example.xml");
$max_per_row = 2;
$item_count = 0;
echo '<table width="100%" border="0" cellspacing="2" cellpadding="2"><tr>';
foreach ($products->item as $item)
{
if ($item_count == $max_per_row)
{
echo "</tr><tr>";
$item_count = 0;
}
echo '<form name="reg" action="metro2.php" method="post"><td width="50%"><b>Name:</b> <input name="fname" maxlength="256" value=" ', $item->name , '" readonly style="width: 300px; border:0;" /><br><img src="' , $item->image, '" alt="Product" height="200"><br>' , '<b>Description:</b> ', $item->description , '<br><b>Left:</b> <input name="left" maxlength="7" value="' , $item->left ,'" readonly style="width: 70px; border:0;" /><br>
<label>
<input type="submit" name="button" id="button" value="Reserve!" />
</label>
</form><br><hr /></td>', PHP_EOL;
$item_count++;
}
echo '</tr>
</table>';
?>
And here is the PHP page for the action of the form. This is metro2.php:
<?php
$products = simplexml_load_file("example.xml");
$fname = $_POST['fname'];
$left = $_POST['left'];
$new_left = $left - 1;
echo 'You want to reserve <b>', $fname, '</b>.<br />';
echo 'There are now only <b>', $new_left, '</b> of this product.';
$products->item->left = $new_left;
$products->asXML("example.xml");
?>
The problem is as follows. If we assume that I have 33 Aiwas and 17 SONYs, if I hit Reserve! for an Aiwa it gives me on metro2.php that 32 Aiwas, remain, but CHANGES THE VALUE of the LEFT ITEMS for the SONY, so when I reload the page metro.php it gives me that I have 33 Aiwas and 32 SONYs... It clearly does not change the value of the correct child of the products... Where is my mistake. I guest somewhere in page metro2.php... But i donno what to do... Please help :) Thanks in advance!