this is my html code
<!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');
$products = $xml->xpath('/products/laptop');
foreach($products as $laptop) {
if($_POST['list'] == $laptop->name) {
global $lname,$detail,$price;
$lname = $laptop->name;
$detail = $laptop->details;
$price = $laptop->price;
}
}
?>
<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="update_p.php" method="post">
<table width="400" border="0" id="tab5">
<tr>
<td colspan="2" align="center">
<select name="list" id="list" >
<?php
foreach($products as $name) {
echo "<option>";
echo $name->name;
echo "</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><label>Product Name</label></td>
<td><?php echo "<input type=\"text\" name=\"p_name\" value=\"{$lname}\" >"; ?></td>
</tr>
<tr>
<td><label>Details</label></td>
<td><textarea name="" cols="" rows="2"><?php echo "$detail"; ?></textarea></td>
</tr>
<tr>
<td>Price</td>
<td><?php echo "<input type=\"text\" name=\"in_price\" value=\"{$price}\" >"; ?></td>
</tr>
</table>
<input type="submit" value="edit" /><input name="" type="reset" />
</form>
</div>
<div class="push"></div>
</div>
<div class="footer">
<p>It Portal (c) 2009</p>
</div>
</body>
</html>
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>HP Pavilion DV6-1350US</name>
<details>15.6-Inch Espresso Laptop - Up to 4 Hours of Battery Life</details>
<price>600$</price>
</laptop>
<laptop>
<name>Dell</name>
<details>15.6-Inch Espresso Laptop</details>
<price>600$</price>
</laptop>
</products>
this is my php
<?php
$doc = new DOMDocument;
$doc->load('../order1.xml');
$laptops = $doc->getElementsByTagName('laptop');
foreach($laptops as $laptop)
{
$name = $laptop->getElementsByTagName('name')->item(0)->textContent;
$details = $laptop->getElementsByTagName('details')->item(0)->textContent;
$price = $laptop->getElementsByTagName('price')->item(0)->textContent;
if($_POST['list'] == $name) {
$doc->documentElement->removeChild($name);
$names = $doc->createElement('name',$_POST['p_name']);
$laptops->appendChild($names);
}
}
$dom->save('../order1.xml');
?>
i need to edit my xml data and i don't know how, what i need to do the user will enter a new data in the text box so the old data will be removed and a new data will be add
i tried to modify the code that "Atli"(another member) helped me with but i failed.