MYSQL Deleting all topics?

Reply

Join Date: Jul 2007
Posts: 253
Reputation: Designer_101 is an unknown quantity at this point 
Solved Threads: 12
Designer_101's Avatar
Designer_101 Designer_101 is offline Offline
Posting Whiz in Training

MYSQL Deleting all topics?

 
0
  #1
Mar 18th, 2009
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
  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. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 93
Reputation: humbug is an unknown quantity at this point 
Solved Threads: 13
humbug's Avatar
humbug humbug is offline Offline
Junior Poster in Training

Re: MYSQL Deleting all topics?

 
0
  #2
Mar 18th, 2009
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)
"If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC