Jump to content

gettting a single value to post from a while loop to delete the corrisponding


son.of.the.morning

Recommended Posts

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?

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.

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.

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;
}
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.