My site's homepage displays all the details of the movies i have in an xml file(performed with a foreach PHP loop,and DOM),i want to add a delete button now for each movie,so that should be done within the loop,the problem is i know how to delete the xml node,given the movie title,but,i can't find a way to transfer the data(movie title) to the page where i could confirm the deletion,i tried some solutions that didnt work:
-I tried a <form method="post" action="foobar"> within the PHP loop,with an <input type="hidden"name="deletion" value="php code giving the movie title"> but as you can see it gives the same name each time the loop runs again,so it obviously will not work.
-Thought about using buttons instead of forms within loop,with onClick event funstions,but i don't want to include js in this at all
-I looked for solutions on forums,i found cookies,sessions,array names...i don't want to use those either,because they aren't effective,since i can't determine which movie title was transfered(because i don't even know the name of the variable that contains it)
Is there any other solution for this problem?would be great PS:i am coding by hand,a friend already told me,that if i was using a framework,it would have been very easy,but i want to learn to code by hand first,then framework.
I can of course provide with code if necessary.
foreach($Movies as $Movie) { ?> <div class="iodata"> <?php echo "Movie : {$Movie->Title}<br /><br />"; echo "Genre : {$Movie->Genre}<br /><br />"; echo "Year : {$Movie->Year}<br /><br />"; echo "Actors : {$Movie->Cast}<br /><br />"; echo "Director : {$Movie->Director}<br /><br>"; echo "Synopsis : {$Movie->Synopsis}<br /><br />";?> <form method="post" action="confirm.php"> <input type="hidden" name="deletion" value="<?php echo "$Movie->Title";?>"> <input type="submit" value="delete this"> </form> </div><br> <?php }}?>
<form method="post">? That should work just fine - it's probably something small.echothe$_POST['deletion']it says,deletion undefined index.<form method='post' action='confirm.php'>- the default isget, which putsdeletionin$_GET. You could also use$_REQUEST, and then it doesn't matter if it's POST or GET.method="post"which is why i mentionned it didnt work,my bad i will edit the post,but still doesnt solve anything though.confirm.php, you'll see thatdeletionhas a different value depending on which submit button you click:echo "<pre>" . print_r( $_POST, 1 ) . "</pre>";