Jump to content


Photo

How to go about deleting post in guestbook


  • This topic is locked This topic is locked
12 replies to this topic

#1 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 July 2006 - 08:08 PM

I'm learning PHP and as l do l add the knowledge that l know into my guestbook, however in the books l am reading however in the books it does not cover deleting a certain post from a guestbook.  Would l have to create a function and then inside that function have the MySQL query and the row id number?  How would l go about making this mini script?

#2 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 08 July 2006 - 08:10 PM

<?php 
mysql_query("DELETE FROM guestbook_table WHERE guestbook_id = ".$_GET['id']." LIMIT 1");
?>

OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#3 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 July 2006 - 08:12 PM

Man looks so simply, feel kinda like an idiot now...

#4 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 08:12 PM

deletepost.php
<?php
//connection stuff
$postid=$_GET['postid'];
mysql_query("DELETE FROM guestbook WHERE postid=$postid");
?>

Now when you are outputting all the messages from the guestbook, if an admin is viewing them, make a link on each post that links to deletepost.php?postid=$id assuming $id is equal to the id of the post you which to delete. If you don't know how to do this, say that here and Ill help you out.

#5 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 08 July 2006 - 08:13 PM

Man looks so simply, feel kinda like an idiot now...


Hope it helps. You could just have a link maybe in an admin panel for each of the entries:

delete.php?id=172


OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#6 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 08:15 PM

Damn Gast, you beat me to it  ;D

#7 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 08 July 2006 - 08:16 PM

Damn Gast, you beat me to it  ;D


Sorry about that :P
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#8 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 July 2006 - 08:19 PM

deletepost.php

<?php
//connection stuff
$postid=$_GET['postid'];
mysql_query("DELETE FROM guestbook WHERE postid=$postid");
?>

Now when you are outputting all the messages from the guestbook, if an admin is viewing them, make a link on each post that links to deletepost.php?postid=$id assuming $id is equal to the id of the post you which to delete. If you don't know how to do this, say that here and Ill help you out.


I would appreciate it if you could help me

#9 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 08 July 2006 - 08:22 PM

Make a file called "delete.php", and in that file put the code that Kurt posted above, changing the table and field names to work with your database.

Then wherever you want to have the delete link/button make it go to "delete.php?id=###" where ### is the ID of that particular record. For example if you were echoing each result:

<?php
$sql = mysql_query("SELECT * FROM guestbook ORDER by id");
while($row = mysql_fetch_assoc($sql)) {
    echo "<a href='delete.php?id=".$row['id']."'>Delete record</a><br />";
}
?>

That should help :P
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#10 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 08:28 PM

I would appreciate it if you could help me

Ok, this is what I would do:

<?php
//connection stuff
$result=mysql_query("SELECT * FROM guestbook ORDER BY postid DESC");
while($msg=mysql_fetch_array($result)){
echo "Posted on {$msg['date']} by {$msg['author']}<br><br>{$msg['message']}";
if($admin==true){//If you are an admin
echo '<a href="deletepost.php?postid='.$msg['postid'].'">Delete This Post</a>';
}
}
?>

That is just a fake guestbook code to show you how you would make a link appear. I can't give you the value of $admin because I don't know how you're keeping track of logged in admins.

#11 dual_alliance

dual_alliance
  • Members
  • PipPipPip
  • Advanced Member
  • 140 posts
  • LocationNSW, Australia

Posted 08 July 2006 - 08:31 PM

Thanks both of you for your help l understand it now.

#12 Gast

Gast
  • Members
  • PipPipPip
  • Advanced Member
  • 131 posts
  • LocationSouth East England

Posted 08 July 2006 - 08:31 PM

Glad I could help :)
OS and Internet Specs:
Windows XP (with SP2), 1680x1050, PHP 4, MySQL 3, Internet Explorer 6 &7 /FireFox 2.0/Opera 9.2

Tutorials:
Simple Introduction to AJAX and XMLHttpRequest
Creating Live Data with AJAX Making a Google Suggest like application

#13 Kurt

Kurt
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationNew York

Posted 08 July 2006 - 08:32 PM

Glad I could help :)

Same here :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users