Jump to content

How to use a button to delete MySQL entries...


Jamrams

Recommended Posts

Hey everyone,

 

I'm fairly new to PHP, so please forgive me if this is an easy topic :P

 

Right, what I've done so far is a kind of staff-only guestbook, so they can post messages to each other and whatever. What I'd like to be able to have is a "Delete" button at the side of each entry which deletes the entry which it is next to. (Anyone can delete any).

 

So, it would look something like this:

 

Entry #1 |Delete|

Entry #2 |Delete|

and so on..(but replace the |Delete| with an <input type="button....> etc)

 

I've tried it myself but I don't know how I would get the button to match the ID or whatever of the entry which it corresponds with.

 

Any help (+ explanations) would be greatly appreciated!

 

Thanks!

Link to comment
Share on other sites

I could be wrong, but to achieve this properly you will have to use javascript

 

Yeah, you're wrong. =P

 

You can just use a link to say, delete.php, and pass an ID to it through GET.

 

<a href="delete.php?id=5">Delete</a>

 

Then, on delete.php, use that ID in a delete query.

Link to comment
Share on other sites

yes you can use php and use an html link that passes the unique ID, but he is wanting to use the html submit input

 

It's really kind of pointless to do it that way, but you could always do it like:

 

<form action="delete.php?id=5" method="post">
<input name="submit" type="submit" value="Delete" />
</form>

 

The link is easier and less of a waste of space though.

 

EDIT: Lol, jonsjava had the same idea. =P

Link to comment
Share on other sites

Thanks for the replies ;)

 

I don't really mind what kind of thing is used...i only said <input type="..."> as an example, I don't mind if it's a link.

 

However, as I said I'm a bit of a newbie in the PHP world, and I haven't used things like delete.php?id=5 so I don't really know what to do xD

 

Sorry for being a pain, but thanks for the fast replies,

~James

Link to comment
Share on other sites

Well, things passed in the URL can be found in the $_GET superglobal.  For example, delete.php?id=5 would have $_GET['id'] set to 5.  Then you'd just do some checking to make sure that it's a number (so no one can do any SQL injection and stuff), and then run your delete query.

Link to comment
Share on other sites

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.