christo16 Posted December 15, 2006 Share Posted December 15, 2006 Hello all I have setup a blog based on php and mysql, it seems to working well. However when I go to delete a post it will only let me delete one post at a time. I have it setup so that you click the check box of the post you want to delete and it adds it to $_GET["variable"] and then deletes it from the DB after it you hit submit. Should I do as a $_POST or is there a better way to do it?Thank you! Link to comment https://forums.phpfreaks.com/topic/30776-php-blog-deleting-posts/ Share on other sites More sharing options...
taith Posted December 15, 2006 Share Posted December 15, 2006 well... that depends... if the delete posts link is protected(admin or whatnot) $_GET[] is easier and faster... if they are open to anybody... use $_POST[] as you cant change the active sourcecode and much harder to hack... Link to comment https://forums.phpfreaks.com/topic/30776-php-blog-deleting-posts/#findComment-141857 Share on other sites More sharing options...
craygo Posted December 15, 2006 Share Posted December 15, 2006 You would have to make the check boxes into an array so they can be set on the processing page.Checkboxes should look something like this[code]<input type=checkbox name=check[] value=$id>[/code]Then on the page that deletes them:[code]<?phpif(isset($_GET['submit'])){$del_array= array();foreach($_GET['check'] as $val){ $del_array[] = $val;}$ids = implode(", ", $del_array);$sql = "DELETE FROM tablename WHERE id IN ($ids)";}?>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/30776-php-blog-deleting-posts/#findComment-141862 Share on other sites More sharing options...
christo16 Posted December 15, 2006 Author Share Posted December 15, 2006 Thank you so much for the help guys, but I still seem to be having trouble with it working, it doesn't seem to delete any now.Here is how my checkbox is setup[code]<Input type=checkbox value=\"$row[0]\" name=\"id\">[/code]And the delete code:[code]<?//Connects to databaserequire_once('../../../db_login.php');if(isset($_GET['submit'])){$del_array= array();foreach($_GET['id'] as $val){ $del_array[] = $val;}$ids = implode(", ", $del_array);mysql_query("DELETE FROM blog WHERE id IN ($ids)'") or die(mysql_error()); }?>[/code]Thanks again! Link to comment https://forums.phpfreaks.com/topic/30776-php-blog-deleting-posts/#findComment-141977 Share on other sites More sharing options...
craygo Posted December 15, 2006 Share Posted December 15, 2006 change[code]<Input type=checkbox value=\"$row[0]\" name=\"id\">[/code]to this[code]<Input type=checkbox value=\"$row[0]\" name=\"id[]\">[/code]Make sure your form has a method of "GET" and you name your submit button[code]<input type=submit name=submit value=submit>[/code]Ray Link to comment https://forums.phpfreaks.com/topic/30776-php-blog-deleting-posts/#findComment-141988 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.