runnerjp Posted June 1, 2008 Share Posted June 1, 2008 here is my code.. but i dont think i have done it right <?php if (isset($_POST['edit'])) { $threadid = mysql_real_escape_string( $_POST['id']); $message = $_POST['message']; echo $message; $query = "UPDATE forumtutorial_posts SET post = '$message' WHERE postid='$threadid' "; echo $query; mysql_query($query) or die('Error, query failed'); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } elseif if(isset($_POST['deletepost'])){ mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'") or die(mysql_error()); }else{ ?> <script src="../../css/SpryCollapsiblePanel.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> <div id="CollapsiblePanel1" class="CollapsiblePanel"> <div class="CollapsiblePanelTab" tabindex="0"> Edit</div> <div class="CollapsiblePanelContent"> <form name='input' action='index.php?page=message&forum=general&id=<? echo $id ?>' method='post'> <input type="hidden" name="id" value="<?php echo $getreplies3['postid'] ?>"> <div align="center"> <label> <textarea class='inputforum' name="message" id="message" cols="500" rows="5"><? echo $message; ?></textarea> </label> <input type='checkbox' name='deletepost'> delete post<br/> <br/> <input type='submit' name='edit' class="submit-btn" value=''/> </div> </form> <? } ?></div> </div> <script type="text/javascript"> <!-- var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1", {contentIsOpen:false}); //--> </script> you see i want it so if <input type='checkbox' name='deletepost'> is ticked then it deletes the post and i thought i would do it by this elseif if(isset($_POST['deletepost'])){ mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'") or die(mysql_error()); but will that detect if ticked do it of not just do if (isset($_POST['edit'])) { Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/ Share on other sites More sharing options...
nloding Posted June 1, 2008 Share Posted June 1, 2008 I could be wrong (guru's, correct me if I am), but I think $_POST['deletepost'] will be set whether it's checked or not, so isset isn't what you want. Instead, add a value to the HTML: <input type="checkbox" name="deletepost" value="deletepost" /> Then, check if $_POST['deletepost'] == 'deletepost'. Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554829 Share on other sites More sharing options...
runnerjp Posted June 1, 2008 Author Share Posted June 1, 2008 ok i gave it ago and <?php if (isset($_POST['edit'])) { $threadid = mysql_real_escape_string( $_POST['id']); $message = $_POST['message']; echo $message; $query = "UPDATE forumtutorial_posts SET post = '$message' WHERE postid='$threadid' "; echo $query; mysql_query($query) or die('Error, query failed'); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } elseif ($_POST['deletepost'] == 'deletepost'){ mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'") or die(mysql_error()); }else{ ?> <script src="../../css/SpryCollapsiblePanel.js" type="text/javascript"></script> <link href="http://www.runningprofiles.com/css/SpryCollapsiblePanel.css" rel="stylesheet" type="text/css" /> <div id="CollapsiblePanel1" class="CollapsiblePanel"> <div class="CollapsiblePanelTab" tabindex="0"> Edit</div> <div class="CollapsiblePanelContent"> <form name='input' action='index.php?page=message&forum=general&id=<? echo $id ?>' method='post'> <input type="hidden" name="id" value="<?php echo $getreplies3['postid'] ?>"> <div align="center"> <label> <textarea class='inputforum' name="message" id="message" cols="500" rows="5"><? echo $message; ?></textarea> </label> <input type="checkbox" name="deletepost" value="deletepost" /> delete post<br/> <br/> <input type='submit' name='edit' class="submit-btn" value=''/> </div> </form> <? } ?></div> </div> <script type="text/javascript"> <!-- var CollapsiblePanel1 = new Spry.Widget.CollapsiblePanel("CollapsiblePanel1", {contentIsOpen:false}); //--> </script> will update the post still so thats all good.... but will not delete post if its checked Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554833 Share on other sites More sharing options...
nloding Posted June 1, 2008 Share Posted June 1, 2008 Take a look at your $treadid variable again. It's not defined within the scope of the elseif. Therefore your query is failing. Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554840 Share on other sites More sharing options...
runnerjp Posted June 1, 2008 Author Share Posted June 1, 2008 ah yes i see...i did this tho elseif ($_POST['deletepost'] == 'deletepost'){ $threadid = mysql_real_escape_string( $_POST['id']); mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'") or die(mysql_error()); and still fails to delet Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554848 Share on other sites More sharing options...
BlueSkyIS Posted June 1, 2008 Share Posted June 1, 2008 echo your SQL to make sure it's what you expect. $sql = "DELETE FROM forumtutorial_posts WHERE postid='$threadid'"; mysql_query($sql) or die(mysql_error()); echo "sql: $sql"; Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554869 Share on other sites More sharing options...
runnerjp Posted June 1, 2008 Author Share Posted June 1, 2008 ah ok hang on iv just relised something <?php if (isset($_POST['edit'])) { $threadid = mysql_real_escape_string( $_POST['id']); $message = $_POST['message']; echo $message; $query = "UPDATE forumtutorial_posts SET post = '$message' WHERE postid='$threadid' "; echo $query; mysql_query($query) or die('Error, query failed'); header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); } elseif ($_POST['deletepost'] == 'deletepost'){ $threadid = mysql_real_escape_string( $_POST['id']); mysql_query("DELETE FROM forumtutorial_posts WHERE postid='$threadid'") or die(mysql_error()); ?> its not even going to elseif ($_POST['deletepost'] == 'deletepost'){ because i keep getting header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554879 Share on other sites More sharing options...
runnerjp Posted June 1, 2008 Author Share Posted June 1, 2008 bmp Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554956 Share on other sites More sharing options...
BlueSkyIS Posted June 1, 2008 Share Posted June 1, 2008 ah ok hang on iv just relised something its not even going to elseif ($_POST['deletepost'] == 'deletepost'){ because i keep getting header( "refresh: 0; url=http://www.runningprofiles.com/members/index.php?page=message&forum=general&id=$id"); then this must always be true: if (isset($_POST['edit'])) { Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554968 Share on other sites More sharing options...
sasa Posted June 1, 2008 Share Posted June 1, 2008 can you post your form code Quote Link to comment https://forums.phpfreaks.com/topic/108240-solved-deleting-from-db-if-checkbox-checked/#findComment-554986 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.