| | |
MYSQL Deleting all topics?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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
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)
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)
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.
★ 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.
![]() |
Similar Threads
- Help me with my myspace clone (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (PHP)
- I NEED HELP PLEASE:Warning: mysql_num_rows(): (MySQL)
Other Threads in the PHP Forum
- Previous Thread: still struggling - please help
- Next Thread: how to install a php script once on a single domain?
Views: 255 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update updates upload url validation validator variable video web xml youtube





