I had to redesign my blog cms with PHP due to JavaScripts inability to save changes to xml files. I need to make a delete function run when you click the delete button. It will delete the specified blog post.
Here is my code so far.
<?
$doc = new DOMDocument();
$doc->load("news.xml");
$channel = $doc->getElementsByTagName("channel");
$channel = $channel->item(0);
$items = $doc->getElementsByTagName("item");
$titles = $doc->getElementsByTagName("title");
$links = $doc->getElementsByTagName("link");
$descriptions = $doc->getElementsByTagName("description");
for($i = 0; $i < $items->length; $i++)
{
$title = simplexml_import_dom($titles->item($i));
$link = simplexml_import_dom($links->item($i));
$description = simplexml_import_dom($descriptions->item($i));
echo "<h6><a href=\"" . $link . "\">" . $title . "</a></h6>";
echo "<p id=\"text\">" . $description . "</p>";
echo "<input type=\"button\" value=\"delete\">";
}
?>
I know i cannot use the action attribute inside of a form because i cannot send the $i variable into the function that way. i need to somehow declare the function during the for loop so that way when i click the button it will execute on a specific value that lived in the $i variable at that time.
Here is the delete blog post code
function removePost($i)
{
$channel->removeChild("$items->item($);
echo "The specified blog post was deleted!";
}


Reply With Quote
Bookmarks