I have an HTML form that calls a PHP document post_remove.php
on submission. post_remove.php
checks a hidden input value value="pst_09-12-2014_07:20:11pm">
to find an id attribute that matches in data.xml
to be removed. id="pst_01-01-2014_05:00:00pm"
I am using a form value to compare. $check = $_POST["validate"] ;
I have tried many alternatives such as loops with no luck and also felt they were unneccesary since I only want one element removed. I can't seem to get any elements to be removed.
My HTML form blog_home.html
:
<div class="blog_wrap">
<p>01-01-2014</p>
<p>05:00:00pm</p>
<h1>My first Blog</h1>
<p>Welcome to my Blog!</p>
<form method="post" action="post_remove.html">
<input type="hidden" name="validate" value="pst_01-01-2014_05:00:00pm">
<input type="submit" name="closer">
</form>
</div>
My XML document data.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<blog>
<posting id="pst_01-01-2014_05:00:00pm">
<date>01-01-2014</date>
<time>05:00:00pm</time>
<title>My first Blog</title>
<content>Welcome to my Blog!</content>
</posting>
<posting id="pst_02-02-2014_06:00:00pm">
<date>02-02-2014</date>
<time>06:00:00pm</time>
<title>My Second Blog</title>
<content>Welcome to my Blog!</content>
</posting>
</blog>
My PHP document post_remove.php
:
<?php
if ( isset( $_POST["closer"] ) )
{
$check = $_POST["validate"] ;
$doc = new DOMDocument() ;
$doc -> load( "data.xml" ) ;
$posting = $doc -> getElementById( $check ) ;// Suspected fault.
$doc -> removeChild( $posting ) ;
$doc -> save( "data.xml" ) ;
header( "Location: blog_home.html" ) ;
}
?>