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

Edited by Psycho
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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