Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-19-2012, 09:41 PM   PM User | #1
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
Deleting comment/forum posts without an admin panel

Below is a script that you can "delete" posts without an admin panel, you use the URL and $_GET[''] instead. The idea is to make removing posts as easy as possible from any computer without bothering with the admin panel.

Features:
  • No admin panel required.
  • All "deleted" posts remain in the database and can be restored by simply changing post status back to the default value of 1.
  • All individual posts have an anchor link. Good for the user who may want to email a link to the post and bookmarking.


How it works:
  • You notice a problem post to remove, in this example post 0003.
  • Click the posts anchor link to display the post id in the URL. index.php?post=0003#0003
  • Replace the #0003 with your delete password. index.php?post=0003password
  • Reload the page.
  • If your delete password is a correct match then the row status is changed to 0.
  • Only posts with a status of 1 will display.


PHP Code:
<?php
if (isset($_GET['post'])){
$post $_GET['post'];
$passWord substr($post, -8); // last 8 characters.
if ($passWord == "password") {
$postId substr($post,0,4); // first 4 characters.
mysql_query("UPDATE posts SET status=0 WHERE id=$postId");
}
}

$sql mysql_query("SELECT * FROM posts WHERE status = '1'");
while(
$row mysql_fetch_array($sql)){
echo 
"<a name=\"$row[0]\"></a>\n";
echo 
"<a href=\"index.php?post=$row[0]#$row[0]\">$row[0]</a><br>\n";
echo 
"$row[1]<br><hr>";
}
?>


-----
__________________
Leonard Whistler
Len Whistler is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:24 PM.


Advertisement
Log in to turn off these ads.