dual_alliance Posted July 8, 2006 Share Posted July 8, 2006 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 https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/ Share on other sites More sharing options...
Gast Posted July 8, 2006 Share Posted July 8, 2006 [code]<?php mysql_query("DELETE FROM guestbook_table WHERE guestbook_id = ".$_GET['id']." LIMIT 1");?>[/code] Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54889 Share on other sites More sharing options...
dual_alliance Posted July 8, 2006 Author Share Posted July 8, 2006 Man looks so simply, feel kinda like an idiot now... Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54890 Share on other sites More sharing options...
Kurt Posted July 8, 2006 Share Posted July 8, 2006 [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 https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54891 Share on other sites More sharing options...
Gast Posted July 8, 2006 Share Posted July 8, 2006 [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 https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54892 Share on other sites More sharing options...
Kurt Posted July 8, 2006 Share Posted July 8, 2006 Damn Gast, you beat me to it ;D Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54893 Share on other sites More sharing options...
Gast Posted July 8, 2006 Share Posted July 8, 2006 [quote author=Kurt link=topic=99894.msg393687#msg393687 date=1152389751]Damn Gast, you beat me to it ;D[/quote]Sorry about that :P Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54896 Share on other sites More sharing options...
dual_alliance Posted July 8, 2006 Author Share Posted July 8, 2006 [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 https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54899 Share on other sites More sharing options...
Gast Posted July 8, 2006 Share Posted July 8, 2006 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 https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54903 Share on other sites More sharing options...
Kurt Posted July 8, 2006 Share Posted July 8, 2006 [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 adminecho '<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 https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54905 Share on other sites More sharing options...
dual_alliance Posted July 8, 2006 Author Share Posted July 8, 2006 Thanks both of you for your help l understand it now. Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54907 Share on other sites More sharing options...
Gast Posted July 8, 2006 Share Posted July 8, 2006 Glad I could help :) Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54909 Share on other sites More sharing options...
Kurt Posted July 8, 2006 Share Posted July 8, 2006 [quote author=Gast link=topic=99894.msg393704#msg393704 date=1152390708]Glad I could help :)[/quote]Same here :) Link to comment https://forums.phpfreaks.com/topic/14045-how-to-go-about-deleting-post-in-guestbook/#findComment-54910 Share on other sites More sharing options...
Recommended Posts