1

I'm trying to add the possibility to delete a selected element from a dropdown menu that is linked to a text field. These elements source is the XML file. I added a DELETE button next to the dropdown menu, so that you can select the name you want, then click DELETE and it needs to delete the selected Signature element in the XML file with the "name" attribute that fits with the value of the dropdown menu.

My jQuery code on the HTML page :

<script type="text/javascript">  
$( document ).ready(function() {
$('#deletenode').click(function(){
  if (confirm('Do you want to delete this name?')) {
     alert('Delete done');
     $.ajax({url: 'delete.php'});
     return true;
    } 
    else 
    {
    alert('Delete cancelled'); 
    return false;
} 
});
});
</script>

My PHP script for deleting the node :

<?php
$xml = simplexml_load_file("signatures.xml");
$name = $_POST['nom'];
$signs = $xml->xpath('//Signature[Nom = "'.$name.'"]');
$xml -> SignaturesParent -> removeChild($signs);
?>

My XML structure :

<SignaturesParent>
<Signature name="John Doe">
<Nom></Nom>
<Title></Title>
</Signature>
<Signature name="John Foo">
<Nom></Nom>
<Title></Title>
</Signature>
</SignaturesParent>

What is not working, is that nothing is getting deleted (obviously). What's wrong in my code? I tried to explain it as simple as possible. Thanks!

Danimp
  • 99
  • 1
  • 8
  • You don't show what happens with `$xml` after the deletion, so it's not to be said in full, but: 1.) it's `@name` and not `Nom` when you formulate the predicate. 2.) Remove child does not work with an array 3.) you don't do any early error handling so most likely many of your problems will happen unnoticed. --- With so many things that can constitute errors for a "not working" situation I close against the reference question that shows how you can obtain better PHP error messages. Especially as you have reposted mutations of this question, please edit and improve this question here for more. – hakre Aug 16 '15 at 14:25

0 Answers0