jgmaddle Posted December 19, 2008 Share Posted December 19, 2008 I am writing a simple script to insert data into mysql via an HTML form and then display it in an HTML table. That part of the script is working perfectly. What I want to do now is add a link or button next to each row in the HTML table that will let me delete that specific row. I know that to accomplish I need to pass the id of the row to be deleted to a varible that can be used in a query string (this is not a something I will be putting online, so I'm not worried about the security of using a query string). The problem is that I don't have a clue how to actually implement this in my code. I have tried a few different ways, and so far nothing has worked. Here is the code of the page I'm trying to implement this on: <?php mysql_connect('localhost', 'username', 'password'); mysql_select_db('network') or die ('Unable to connect to database: ' . mysql_error()); $query="SELECT * FROM ipaddrs"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); ?> <table border="0" cellspacing="5" cellpadding="5"> <tr> <th><font face="Arial, Helvetica, sans-serif">ID</font></th> <th><font face="Arial, Helvetica, sans-serif">IP Address</font></th> <th><font face="Arial, Helvetica, sans-serif">Port</font></th> <th><font face="Arial, Helvetica, sans-serif">Router</font></th> <th><font face="Arial, Helvetica, sans-serif">FW Version</font></th> <th><font face="Arial, Helvetica, sans-serif">Username</font></th> <th><font face="Arial, Helvetica, sans-serif">Password</font></th> <th><font face="Arial, Helvetica, sans-serif">Notes</font></th> <th><font face="Arial, Helvetica, sans-serif">Delete</font></th> </tr> <?php $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); $ip=mysql_result($result,$i,"ip"); $port=mysql_result($result,$i,"port"); $router=mysql_result($result,$i,"router"); $fwversion=mysql_result($result,$i,"fwversion"); $user=mysql_result($result,$i,"user"); $pass=mysql_result($result,$i,"pass"); $notes=mysql_result($result,$i,"notes"); ?> <tr> <td><font face="Arial, Helvetica, sans-serif"><?php echo $id; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $ip; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $port; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $router; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $fwversion; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $user; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $pass; ?></font></td> <td><font face="Arial, Helvetica, sans-serif"><?php echo $notes; ?></font></td> <?php $i++; } echo "</table>"; ?> Any help that anyone can offer would be greatly appreciated. I've been stuck on this one for a couple of days now. -Jason Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/ Share on other sites More sharing options...
ngreenwood6 Posted December 19, 2008 Share Posted December 19, 2008 You could modify this link: <td><font face="Arial, Helvetica, sans-serif"><?php echo $id; ?>< a href="delete.php?id='<?php echo $id; ?>'">Delete</a></font></td> That would take you to a delete.php page with the id in the url. Then on the delete page you would use a get method to get the id and then use the id to delete the record using a query and redirect you to a page that says the record was deleted. Hopefully that will help. Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-719830 Share on other sites More sharing options...
jgmaddle Posted December 20, 2008 Author Share Posted December 20, 2008 Thank you very much. I was finally able to make it work by doing it that way. You're the first person I've had make a suggestion that wasn't loaded down with a million technical terms and ideas that I'm too new to get. . Thanks again. -Jason Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720078 Share on other sites More sharing options...
ngreenwood6 Posted December 20, 2008 Share Posted December 20, 2008 no problem simple answer to a well laid out question. Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720088 Share on other sites More sharing options...
redarrow Posted December 20, 2008 Share Posted December 20, 2008 That is a floored code, unless your the only one got access to delete the database entrys.. You need to use a session for the users id to delete entry or your get a clever person come along and delete other users database rows... Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720093 Share on other sites More sharing options...
ngreenwood6 Posted December 20, 2008 Share Posted December 20, 2008 I would assume that he was only allowing the person that needs to delete the entry access to it. He asked a question and it was answered. Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720098 Share on other sites More sharing options...
redarrow Posted December 20, 2008 Share Posted December 20, 2008 what happens when he start loosing money, When his database get deleted entry's, you no as well as me your suggestion is only a suggestion, and other users like my self like to point out possibility that could happen. good advice is always welcomed, also as been told my self thousand times, a problem never solved until the post owner says so. dosent matter if a user is logged in, the point is it deleting a database entry via a url id, what can be changed via any user looged in knowing any bodys id... Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720102 Share on other sites More sharing options...
ngreenwood6 Posted December 20, 2008 Share Posted December 20, 2008 It can't be deleted if it is in an admin section. sure it is passed through the url but one would assume that on his delete.php page he would have something like this: if($user == "admin") { delete the record } And more than likely he is just learning the how to do something like that and is testing. Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720371 Share on other sites More sharing options...
jgmaddle Posted December 20, 2008 Author Share Posted December 20, 2008 Redarrow, thank you for wanting to let me know about a possible issue with the code, but as I stated in my first post I am not planning to make this script avalible to anyone besides myself, so security isn't much of a concern. I was simply focused on getting the delete function to work at all in a way that I could actually understand how it was happening. Also, I am new to these forums and only just noticed that some of the posts are marked as "solved". I do consider my question answered and the problem solved, I simply don't know how to mark it as such, or even if I can do that myself. Again, ngreenwood, thank you for the response, you were a big help. -Jason Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720505 Share on other sites More sharing options...
ngreenwood6 Posted December 20, 2008 Share Posted December 20, 2008 No problem. If you look at the bottom left side of the page on this post you will see a button that says topic solved. If you click it will mark it as solved. Link to comment https://forums.phpfreaks.com/topic/137712-solved-link-to-delete-mysql-row/#findComment-720509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.