Jump to content

[SOLVED] Click Link to Delete Record


xProteuSx

Recommended Posts

I am trying to add a function to one of my scripts.  I would like to be able to click a link and have it delete a particular row from by DB.  Links are generated by a PHP script and are based on entries on a DB.  In this DB I have a column called 'users'.  The table is generated by the following snippet:

 

echo '<table>';

while($row = mysql_fetch_row($result))

{

echo '<tr>';

echo '<td> ' . $row[0] . '</td>';

echo '<td bgcolor=blue> <a href="http://www.microsoft.com/' . $row[0] .'">Delete</a></td>';

echo '<td bgcolor=blue> <a href="http://www.microsoft.com/' . $row[0] .'">Edit</a></td>';

echo '<td bgcolor=blue> <a href="http://www.microsoft.com/' . $row[0] .'">View</a></td>';

echo '</tr>';

}

echo '</table>';

 

So if the username value in row #1 is 'user1' the HTML reads kind of like this:

 

<table>

<tr>

<td><a href="http://www.mcatzone.com/user1'">Delete</a></td>

<td><a href="http://www.mcatzone.com/user1'">Edit</a></td>

<td><a href="http://www.mcatzone.com/user1'">View</a></td>

</tr>

</table>

 

What I would like to do is have a link that will delete the entire row for 'user1' from the DB.  I think you all know what I mean.

 

I have no idea where to start ...

Link to comment
Share on other sites

As you explained, your URLs look like this

http://www.mcatzone.com/user1'

 

They should look something like this

http://www.mcatzone.com/your_script.php?delete=user1

 

Then on "your_script.php", you would put the following code.

 

<?php

if(isset($_GET['delete'])){
   $delete = $_GET['delete'];
   $query = mysql_query("DELETE FROM table WHERE username='$delete'")or die(mysql_error());
   echo "Deleted";
}

?>

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.