Jump to content

How to go about deleting post in guestbook


dual_alliance

Recommended Posts

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?
Link to comment
Share on other sites

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

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 [i]deletepost.php?postid=$id[/i] 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.
Link to comment
Share on other sites

[quote author=dual_alliance link=topic=99894.msg393683#msg393683 date=1152389537]
Man looks so simply, feel kinda like an idiot now...
[/quote]

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

delete.php?id=172

Link to comment
Share on other sites

[quote author=Kurt link=topic=99894.msg393684#msg393684 date=1152389577]
[u]deletepost.php[/u]
[code]
<?php
//connection stuff
$postid=$_GET['postid'];
mysql_query("DELETE FROM guestbook WHERE postid=$postid");
?>
[/code]

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 [i]deletepost.php?postid=$id[/i] 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.
[/quote]

I would appreciate it if you could help me
Link to comment
Share on other sites

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:

[code]<?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 />";
}
?>[/code]

That should help :P
Link to comment
Share on other sites

[quote author=dual_alliance link=topic=99894.msg393693#msg393693 date=1152389953]
I would appreciate it if you could help me
[/quote]
Ok, this is what I would do:

[code]
<?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>';
}
}
?>
[/code]

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.
Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.