Hi

The user clicks on a buttons to delete all posts in a thread (this also deletes the parent post). The code is bellow. This however isnt working, its deleting all the parent posts, even those that dont correspond to the topic clicked on. Any ideas

if (isset ($_GET['delete']) && $_GET['delete'] == true) {
$id=$_GET['postid'];

$query = "DELETE FROM forum WHERE postid = '$id' OR parentid = '$id'";
if (mysql_query($query)) {
echo "<p width=700px>You have succesfully deleted the topic. Thankyou for keeping the forum clean. <br><a href='forum.php'>Back to forum</a><br><img src='images/tick.png'>";
include 'include/bottom.php';
die();
}
else 
$msg = "<p width=700px>You have tried to delete this message. However the following is stoping you: <br> <h3>Incorrect Priviledges</h3><br><a href='forum.php'>Back to forum</a><br><img src='images/cross.png'> "; 
include 'include/bottom.php';
die();
}

How is your database set up? That will only work if
1. postid is unique to each post and parentid holds the id of the parent post and NULL if it is itself a parent post.
OR
2. parentid is set to the id of the topic for the parent post only (NULL otherwise) and postid holds the id that parentid holds but is set for child posts instead.

And of course, you pass the parent id to the script. Its hard to tell what's going wrong without knowing without knowing a bit more as the query seems ok.

(The query should only be "WHERE postid = '3' " if postid is a string, otherwise you should remove the single quotes)

This article has been dead for over six months. Start a new discussion instead.