delete based on input
Posted: Sun Jan 03, 2010 7:41 pm
i have a xml sheet that has links ..i m trying to delete the line from the xml based on line generated from the values i enter in the text field . wat its doing currently is it doesnt delete and gives and error undefined offset:8
please help
my xml file is as follows:-
please help
Code: Select all
<?php
$myheading="";
$mylink="";
$mybody="";
if (isset($_POST['submit'])) {
$mylink = $_POST["link"];
$myheading = $_POST["heading"];
$mybody = '<image heading="'.$myheading.'" links="'.$mylink.'"/>';
$start = "<gallery>";
$end = "</gallery>";
$file = "article.xml";
$i=$len=0;
$arr=array();
$handle = fopen($file, "r");
if ($handle) {
while (!feof($handle)) {
$temp = fgets($handle);
if ($temp=="$start"){
$arr[$i]="$start";
$i++;
}
if($temp=="$end"){ $arr[$i]="";
$i++;
}
if ($temp !="$start" && $temp !="$end" && $temp != $mybody){
$arr[$i]="$temp";
$i++;
}
}
$len=$i;
fclose($handle);
}
$handle = fopen($file,"w");
if ($handle) {
$i=0;
while ($i<=$len) {
fwrite($handle,$arr[$i]);
$i++;
}
fwrite($handle,"\n$end");
fclose($handle);
$process="complete";
}
else {
$process="incomplete";
}
}
?>
<table id="structure">
<tr>
<td id="page">
<h2>delete data</h2>
<?php if (!empty($process)) {echo "<p class=\"message\">" . $process . "</p>";} ?>
<form action="delete_p.php" method="post">
<table>
<tr>
<td>heading</td>
<td><input type="text" name="heading" maxlength="23" value="<?php echo htmlentities($myheading); ?>" /></td>
</tr>
<tr>
<td>links</td>
<td><input type="text" name="link" maxlength="40" value="<?php echo htmlentities($mylink); ?>" /></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="delete data" /></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
Code: Select all
<gallery>
<image heading="google" links="google"/>
<image heading="rediff" links="rediff"/>
<image heading="g" links="g"/>
<image heading="jerk" links="jerk"/>
<image heading="jack" links="jack"/>
</gallery>