Jamrams Posted September 24, 2008 Share Posted September 24, 2008 Hey everyone, I'm fairly new to PHP, so please forgive me if this is an easy topic 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! Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted September 24, 2008 Share Posted September 24, 2008 I could be wrong, but to achieve this properly you will have to use javascript Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 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. Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted September 24, 2008 Share Posted September 24, 2008 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 Quote Link to comment Share on other sites More sharing options...
jonsjava Posted September 24, 2008 Share Posted September 24, 2008 <form method="POST" action="delete.php?id=5"><input type="submit" value="Delete"></form> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 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 Quote Link to comment Share on other sites More sharing options...
dennismonsewicz Posted September 24, 2008 Share Posted September 24, 2008 ah I agree with Darkwater... So is that how this forum is doing the post and preview buttons? Quote Link to comment Share on other sites More sharing options...
Jamrams Posted September 24, 2008 Author Share Posted September 24, 2008 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 Quote Link to comment Share on other sites More sharing options...
DarkWater Posted September 24, 2008 Share Posted September 24, 2008 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. Quote Link to comment 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.