Jump to content

Need Some help please !


HellFire100x

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'] . ""); }   } 

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

Archived

This topic is now archived and is closed to further replies.

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