son.of.the.morning Posted December 6, 2011 Share Posted December 6, 2011 i have a while loop that builds up a table of records, each row has a button that needs to have an action to delete that specific record. I can think of the obvious way around this and add a form around each row and set the button to type="submit". However there is a problem i have the entire table of records wrapped within in a form object for other functionalities. Does anyone have a solution for this problem? Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/ Share on other sites More sharing options...
ddubs Posted December 6, 2011 Share Posted December 6, 2011 You could have an anchor instead that creates a link to a delete script, like: <a href="./?action=delete&id=1">Delete</a> Whenever I use this kinda of functionality, im careful to do a header(location: "./") redirect as soon as the function completes successfully so that people cant refresh and have the function execute multiple times. Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/#findComment-1294888 Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 It's actualy a form button though, can i apple a link to it? Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/#findComment-1294889 Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 I understand were your comming from but i dont want to submit the id from another page i want it to post to the current page and use isset($_post). Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/#findComment-1294890 Share on other sites More sharing options...
Adam Posted December 6, 2011 Share Posted December 6, 2011 You should just use a link (and technically if you follow REST practises that is how you should do it - through the URL). If you're worried about tampering with the URL to delete other items, then surely they user could just go back and click the button on the item they wish to delete? Permission checks should prevent them deleting anything they shouldn't be able to. Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/#findComment-1294892 Share on other sites More sharing options...
ddubs Posted December 6, 2011 Share Posted December 6, 2011 You can have the link direct back to the same page it was called from, but instead of checking $_POST, you'll check $_GET for your data. Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/#findComment-1294894 Share on other sites More sharing options...
son.of.the.morning Posted December 6, 2011 Author Share Posted December 6, 2011 I just tried this approach and it doesnt seem to be working to well for me. This is what i have just done... The link <a href="?id=<?php echo $record_rows['id']; ?>">delete me</a> Post check <?php if(isset($_POST['id'])) { $DeleteId = $_POST['id']; echo $DeleteId; } ?> Link to comment https://forums.phpfreaks.com/topic/252575-gettting-a-single-value-to-post-from-a-while-loop-to-delete-the-corrisponding/#findComment-1294897 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.