this is my php code

extract($_POST);
$doc = new DOMDocument;
$doc->load('../order1.xml');

$laptops = $doc->documentElement;


foreach($laptops as $laptop){
if($list==$laptop->name) {

$name1 = $laptop->name;
$oldnam = $laptop->removeChild($name1);
$olddetails=$laptop->removeChild($laptop->details);
$oldprice=$laptops->removeChild($laptop->price);

$name1 = $laptops->getElementsByTagName('name')->item(0);
$oldname = $laptops->removeChild($name1);
}}
$doc->save("../order2.xml");

this is my xml

<?xml version="1.0"?>
<?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>dellllllllll</name>
		
        <details>
			15.6-Inch Espresso Laptop - Up to 4 Hours of Battery Life (Windows 7 Home Premium)
		</details>
		
        <price>600$</price>

	</laptop>	
</products>
<!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('../order1.xml');

     $names = $xml->xpath('/products/laptop/name');	
	
?>  

<meta name="delete" content="deleting products" />
<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="delete_pp.php" method="post">
<table width="400" border="0" id="tab5">
  <tr>
  	<td colspan="2" align="center">
    
<select name="list" id="list" >
    
<?php
	
foreach($names as $name) {
			
echo "<option>";
echo $name;
echo "</option>";
}

?>
      
    </select>
    
    &nbsp;</td>
    </tr>
  <tr>
    <td><label>Product Name</label></td>
    <td><input name="" type="text" value="HP Pavilion" /></td>
  </tr>
  <tr> 
    <td><label>Details</label></td>
    <td><textarea name="" cols="" rows="2">HP Pavilion DV6-1350US 15.6-Inch Espresso Laptop - Up to 4 Hours of Battery Life (Windows 7 Home Premium)</textarea></td>
  </tr>
  <tr>
    <td>Price</td>
    <td><input name="" type="text" value="600$" /></td>
  </tr>
  <tr>
    <td>Image</td>
    <td><input type="file" value="../images/hp3_120._V228873826_.jpg"/></td>
  </tr>
</table>
<input name="" type="submit" value="Delete" /><input name="" type="reset" />
</form>
</div>

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

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

</body>
</html>

i want to delete the selected item from the drop down list but its not working

Hey.

I think you may be mixing up the DOMDocument and SimpleXML syntax in your PHP code.
The $xml->element[0]->attribute syntax is from the SimpleXML class, and won't work with DOMDocument objects.

Try something more like:

<?php
$doc = new DOMDocument;
$doc->load('../order1.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('../order2.xml');
?>

Note that I removed your extract($_POST) as well. This is a horrible habit to get used to, and might even compromise the security of your code. (Which is why the register_globals feature - which is what your extract code replicates - has been made deprecated, and removed from future versions.)

commented: thank you for your help,now it works. +0
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.