Jump to content

Need to add a 'delete' button to user-specific MySQL data


Recommended Posts

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 by eklem

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 by mac_gyver
fixed wording
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.