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
https://forums.phpfreaks.com/topic/78632-solved-click-link-to-delete-record/
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";
}

?>

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.