Jump to content

Recommended Posts

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 by HellFire100x
Link to comment
https://forums.phpfreaks.com/topic/278490-need-some-help-please/
Share on other sites

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.

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']

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.