eklem Posted October 22, 2014 Share Posted October 22, 2014 (edited) Hello, First of all I'd like to say thank you for all the great information on the forums, I've been reading a lot on here lately. I've started to make a website where users can log in and submit items to a database, which is then displayed on another page. If Tom and Bill both post 10 items, all 20 items will be displayed on the "listings" page, however on the main log in screen Tom will only see his own 10 items and Bill will see his own 10 items. This is all working perfectly, however, I now need to add a delete button so that they can delete specific items. I have loosely followed this tutorial here to get the table to display as I want it (amongst a few other things, such as the user logins) http://www.wickham43.com/tutorial-php-xhtml/formphptomysql.php I've added the delete button in the PHP loop for each row, I just can't figure out how to delete the specific row when clicked. Any help would be really appreciated Edited October 22, 2014 by eklem Quote Link to comment https://forums.phpfreaks.com/topic/291981-need-to-add-a-delete-button-to-user-specific-mysql-data/ Share on other sites More sharing options...
mac_gyver Posted October 22, 2014 Share Posted October 22, 2014 (edited) in general, to delete information you would - 1) make a post method form (you are modifying data on the server, so by definition, post method should be used.) the form should submit the id of the row you want to delete. 2) your form processing code would first make sure that there is a currently logged in user, then make sure that a form was submitted, take the submitted id value, validate that it is of an expected type/value, then use it in the WHERE clause in a delete query. 3) the delete query would include a condition in the WHERE clause to make sure that the current logged in user OWNS the row that's being deleted to prevent anyone from deleting rows that are not their own. without seeing your code, it's not directly possible to help you with what it might or might not be doing. Edited October 22, 2014 by mac_gyver fixed wording Quote Link to comment https://forums.phpfreaks.com/topic/291981-need-to-add-a-delete-button-to-user-specific-mysql-data/#findComment-1494379 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.