HellFire100x Posted May 28, 2013 Share Posted May 28, 2013 (edited) i'm a beginner at php coding so this is what i've created.. well to be simple..i need to create a delete button for every post and i have created a button..but when i click that button all posts get deleted what i'm basically doing is that..i'm making a submit button appear beside every post..but when i click one button all of them are getting deleted...can u correct the code ? its like the button only has to delete the post to which it was assigned to..thanks alot.. while($row = mysql_fetch_assoc($result)){ echo '<tr>';echo '<td class="leftpart">';echo '<h3><a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br /><h3>';echo '</td>';echo '<td class="rightpart">';echo date('d-m-Y', strtotime($row['topic_date']));echo '</td>'; echo '</tr>';if($_SESSION['signed_in'] == true && $_SESSION['user_level'] == 1 ){ echo '<form name="form" method="post"> <td><input type="submit" NAME="button1" value="Delete" /></td></form>';if(isset($_POST['button1'])){ mysql_query("DELETE FROM topics WHERE topic_id=" . $row['topic_id'] . ""); } } Edited May 28, 2013 by HellFire100x Quote Link to comment https://forums.phpfreaks.com/topic/278490-need-some-help-please/ Share on other sites More sharing options...
computermax2328 Posted May 28, 2013 Share Posted May 28, 2013 Take your if(isset()) out of the while loop. What you want to do is have the page say if(isset(submit button) then delete this entry based off of the id that is provided from the form. Then if the submit button is not set loop through these entries. Quote Link to comment https://forums.phpfreaks.com/topic/278490-need-some-help-please/#findComment-1432798 Share on other sites More sharing options...
jcbones Posted May 28, 2013 Share Posted May 28, 2013 In order to implement the changes in the above post, which is the correct way to do it, then you need to set a hidden input in the form with the post id. Also, some browsers don't send submit button info the same as others, so I would suggest using $_SESSION['REQUEST_METHOD'] Quote Link to comment https://forums.phpfreaks.com/topic/278490-need-some-help-please/#findComment-1432800 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.