View Full Version : HELP: deleting messages
ErikvD
05-21-2003, 11:32 PM
I've created a page that adds and displayes messages from a database (mysql). When all the messages are on the page I want to be able to have a link just above/below every message from which you can delete that single message.
Does anyone know how this can be done without the use of a form with radiobuttons?
mordred
05-22-2003, 12:14 AM
Use a standard link that points to your deletion script, and append the message's id to the URL of that link, like deleteMessage.php?msgId=4711.
On the next page, retrieve the message id with $_GET['msgId'].
Nightfire
05-22-2003, 12:15 AM
You'd have links like this
<a href="deletepost.php?postid=1">Delete this post</a>
Then in deletepost.php
//connect to database
mysql_connect(...)
mysql_select_db(...)
$sql = "DELETE FROM tablename WHERE postid='$_GET[postid]'";
$query = mysql_query($sql);
if($query){
echo 'Post deleted.';
}
Of course, you'd need to check if the post id exists before you try deleting it, but I've just thrown together something you can work from
ErikvD
05-22-2003, 02:12 PM
Thanks, there was some trial and error to get the right postid, but finally it worked!
Great help guys!
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.