Jump to content

PH MSSQL delete row with a link


laural

Recommended Posts

I hope this question has a simple answer.  I have a table of names that pulls back records that are in a table.  I want to add a link by the name that says "Remove" - when clicked, I would like the name deleted from the mssql table and the page left to reflect the list without that name. 

 

Is there an easy way to accomplish this?  Even if I cannot remain on the same page, how would I do that using a link?  Thanks!!!

Link to comment
https://forums.phpfreaks.com/topic/278219-ph-mssql-delete-row-with-a-link/
Share on other sites

Here is a vry simplistic solution:

 

When you output the records create the delete links like so

<a href="?deleteID=XXX">Delete</a>

Where "XXX" is the unique id of the record to be deleted by that link.

 

Then on the code to render the page, put something like this as the top io the script (before the output is generated).

if(isset($_GET['deleteID']))
{
    $deleteID = intval($_GET['deleteID'];
    $query = "DELETE FROM table WHERE id = $deleteID";
    $result = mysql_query($query);
}

This will refresh the page when clicking a link. If you want to not refresh the page, then you wuold use the same logic using an AJAX solution.

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.