Jump to content

Recommended Posts

Greetings,

 

I am trying to delete a record from my xml file.  The display is correct with the delete button but it not delete.

 

Any  help.

 

 

<html>
<head></head>
<body>
<?php
    $xmldoc = new DOMDocument();
    $xmldoc->load('gallery.xml', LIBXML_NOBLANKS);

    $count = 0;

    $activities = $xmldoc->firstChild->firstChild;
    //prints the list of activities, with checkboxes on the left for each item
    //the $count variable is the id to each entry
    if($activities!=null){
        echo '<form name=\'erase\' action=\'delete.php\' method=\'post\'>' . "\n";
        while($activities!=null){
            $count++;
            echo "    <input type=\"checkbox\" name=\"activity[]\" value=\"$count\"/>";
            echo ' '.$activities->textContent.'<br/>'."\n";
            $activities = $activities->nextSibling;
        }
        echo '    <input type=\'submit\' value=\'erase selected\'>';
        echo '</form>';
    }
?>
//section used for inserting new entries. this feature is working as expected.
<form name='input' action='idelete.php' method='post'>
    insert activity:
    <input type='text name='activity'/>
    <input type='submit' value='send'/>
    <br/>
</form>
</body>
</html>

 

delete.php

<?php
    $xmldoc = new DOMDocument();
    $xmldoc->load('sample.xml', LIBXML_NOBLANKS);

    $atvID = $_POST['activity'];

    foreach($atvID as $id){
        $delnode = $xmldoc->getElementsByTagName('activity');
        $xmldoc->firstChild->removeChild($delnode->item($id));
    }

    $xmldoc->save('gallery.xml');
?>


You have two different ways of coming up with activities (counting nodes versus a search on //activity), which isn't all that surprising since you're using two different XML files. What's up with that?

 

[edit] And what does any of this have to do with "display image instead of image file name"?

Greetings,

 

My apologies, the subject was for a post that i was going to send, however I figured that out and placed this post forgetting to change the subj.

 

The First Code listing is the load form from my xml file... not posted. and the second is the delete.php file.

the xml looks like this:

 


<list>
    <activity>swimming</activity>
    <activity>running</activity>
    <activity>soccer</activity>
</list>

[code]

Any help would be fine.  I just want to delete the entries from the check box.

ALso, I thank you for replying... if you find yourself unable to assist me any further without solving, please let me know so I could move on to a different strategy.  I know you're communication with many others... I just want to finish this 4 day journey of just displaying data from man xml file and edit and deleting them.  I've got the adding down.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.