nezbo Posted July 4, 2007 Share Posted July 4, 2007 Hi all I have this code and i want to beable to when i click the delete link to delete the row that is selected in the database? Any help please? $result = mysql_query("SELECT * FROM person ORDER BY UserName ASC"); echo "<table border=1 align=center>"; echo "<tr><td colspan=8 align=center><h2>All users registered with the system.</h2><tr><td>"; while ($row = mysql_fetch_array($result)) { echo "<tr><td align=left><a href=editUser.php?user_identifier=$row[CallID] >$row[CallID] </a>" . "</td><td align=left>" . $row['UserName'] . "</td><td align=left>" . $row['FullName'] . "</td><td align=left>" . $row['EmailAddress'] . "</td><td align=left>" . $row['ContactNumber'] . "</td><td align=left>" . $row['UserLevel'] . "</td><td align=left> <a href=#>Delete</a>" . "</td></tr>"; } echo "</table>"; Neil Link to comment https://forums.phpfreaks.com/topic/58379-delete-rows-from-while-statment/ Share on other sites More sharing options...
GingerRobot Posted July 4, 2007 Share Posted July 4, 2007 Well im guesing that your 'CallID' field is a unique field? If so, just pass that into the query string, as you do for your editUser.php page, and delete the row: <?php $id = $_GET['CallID']; mysql_query("DELETE FROM `person` WHERE `CallID`='$id'") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/58379-delete-rows-from-while-statment/#findComment-289454 Share on other sites More sharing options...
nezbo Posted July 4, 2007 Author Share Posted July 4, 2007 cool cheers does this mean i need to creat a form type of thing to instrd of using a <a href.... ? Well im guesing that your 'CallID' field is a unique field? If so, just pass that into the query string, as you do for your editUser.php page, and delete the row: <?php $id = $_GET['CallID']; mysql_query("DELETE FROM `person` WHERE `CallID`='$id'") or die(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/58379-delete-rows-from-while-statment/#findComment-289462 Share on other sites More sharing options...
GingerRobot Posted July 4, 2007 Share Posted July 4, 2007 No not at all. Get variables are passed to a page in the URL. If you specify the form method as get, all it actually does it put the contents of the form in the url. You would make your links something like: echo "<a href='deleteuser.php?id=$row[CallID]'>$row[CallID]</a>"; Link to comment https://forums.phpfreaks.com/topic/58379-delete-rows-from-while-statment/#findComment-289626 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.