xProteuSx Posted November 24, 2007 Share Posted November 24, 2007 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 More sharing options...
pocobueno1388 Posted November 24, 2007 Share Posted November 24, 2007 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 https://forums.phpfreaks.com/topic/78632-solved-click-link-to-delete-record/#findComment-397894 Share on other sites More sharing options...
xProteuSx Posted November 24, 2007 Author Share Posted November 24, 2007 Thanks a ton. Beautiful! Link to comment https://forums.phpfreaks.com/topic/78632-solved-click-link-to-delete-record/#findComment-397899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.