943,987 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 410
  • PHP RSS
Mar 18th, 2009
0

MYSQL Deleting all topics?

Expand Post »
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
PHP Syntax (Toggle Plain Text)
  1. if (isset ($_GET['delete']) && $_GET['delete'] == true) {
  2. $id=$_GET['postid'];
  3.  
  4. $query = "DELETE FROM forum WHERE postid = '$id' OR parentid = '$id'";
  5. if (mysql_query($query)) {
  6. 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'>";
  7. include 'include/bottom.php';
  8. die();
  9. }
  10. else
  11. $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'> ";
  12. include 'include/bottom.php';
  13. die();
  14. }
Similar Threads
Reputation Points: 12
Solved Threads: 16
Posting Whiz
Designer_101 is offline Offline
314 posts
since Jul 2007
Mar 18th, 2009
0

Re: MYSQL Deleting all topics?

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)
Reputation Points: 20
Solved Threads: 13
Junior Poster in Training
humbug is offline Offline
93 posts
since Oct 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: still struggling - please help
Next Thread in PHP Forum Timeline: how to install a php script once on a single domain?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC