sample of my xml

<?xml version = "1.0" encoding="UTF-8"?>
<?xml-stylesheet type = "text/xsl" href = "input.xsl"?>


<products>
    <laptop>
        <name>hp </name>
		
        <details>
			15.6-Inch Espresso Laptop - Up to 4 Hours of Battery Life (Windows 7 Home Premium)
		</details>
		
        <price>600$</price>
    </laptop>
    <laptop>
        <name>dell vostro</name>
		
        <details>
			17-Inch 
		</details>
		
        <price>600$</price>
    </laptop>
	
	 <laptop>
        <name>acer aspire </name>
		
        <details>
			15.4-Inch 
		</details>
		
        <price>600$</price>
    </laptop>
    
</products>

the html is as follows

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<?php
	
	 $xml = simplexml_load_file('order.xml');

     $names = $xml->xpath('/products/laptop/name');	
		
?>  
<meta name="update" content="updating products data" />
<title>index</title>
<link href="../includes/styles.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="Container">

<h1>The IT Portal</h1>

<div id="navbar"> 
  <ul> 
    <li><a href="../index.html">Home</a></li> 
    <li><a href="../products.html">Products</a></li> 
    <li><a href="../new_arrivals.html">New Arrivals</a></li> 
    <li><a href="../about.html">About us</a></li> 
    <li><a href="../Search.html">Search</a></li>
    <li><a href="../Register.html">Register</a></li>
    <li><a href="../login.html">LOGIN</a></li> 
  </ul> 
 </div>
 
<div id="con1">
<form action="update_p.php" method="post">
<table width="400" border="0" id="tab5">
  <tr>
  	<td colspan="2" align="center">
    
    
    
    
    
<?php
//foreach($detail as $details) {
			
//echo"$details";
//$det = $details;

//}
//$details = $xml->xpath('/products/laptop/details');	

echo"$det";


	echo " <select name=\"list\" id=\"list\" onchange=\"details.value = \"{$det}\">    ";
	
foreach($names as $name) {
			
echo "<option>";
echo $name;
echo "</option>";
}

?>
      
    </select>
    &nbsp;</td>
    </tr>
  <tr>
    <td><label>Product Name</label></td>
    <td><input name="pname" type="text" value="" id="pname" /></td>
  </tr>
  <tr> 
    <td><label>Details</label></td>
    <td><textarea name="details" cols="" rows="2"></textarea></td>
  </tr>
  <tr>
    <td>Price</td>
    <td><input name="pprice" type="text" value="" id="pprice" /></td>
  </tr>
  <tr>
    <td>Image</td>
    <td><input type="file" value=""/></td>
  </tr>
</table>
<input type="submit" value="Update" /><input name="" type="reset" />
</form>
</div>

<div class="push"></div>
 
</div>

<div class="footer">
      <p>It Portal (c) 2009</p>
</div>

</body>
</html>

the php file is my problem
it is supposed to delete product and add a replacement for it

<?php
extract($_POST);
$doc = new DOMDocument;
$doc->load('order.xml');

$laptops = $doc->getElementsByTagName('laptop');

foreach($laptops as $laptop)
{
    $name = $laptop->getElementsByTagName('name')->item(0)->textContent;
    if($_POST['list'] == $name)
    {
		
        $doc->documentElement->removeChild($laptop);
    }
}

//$doc->save('order.xml');





//$doc = new DOMDocument;
//$doc->load('order.xml');

$root = $dom -> getElementsByTagName('products');
$root = $dom->documentElement;

$element = $dom->createElement("laptop");
$root->appendChild($element);

$pname = $dom->createElement('Name',$tname);
$element->appendChild($pname);

$details = $dom->createElement('details',$detail);
$element->appendChild($details);

$price = $dom->createElement('price',$price);
$element->appendChild($price);

$doc->save('order.xml');
echo "saved after add";


?>

the php file is my problem
it is supposed to delete product and add a replacement for it

What is it doing instead? Do you get any errors?

Why don't you store the data in a database, then make a PHP script that converts from MySQL results to XML? You'll need to use PHP's header function to change the document type.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.