rebecca09 Posted March 25, 2010 Share Posted March 25, 2010 I am having difficulties with the delete button on a forum page! I have managed to create a button that will delete the forum posts, but instead of just deleting each row when you select each delete button on the row, it deletes all the forum posts! Could anyone take a quick look at the code below and see if you know where I’m going wrong. I’m guessing its the query in the delete.php file because the query makes the button delete ALL posts rather than the single one on the row. Here is the code used in the forum.php page (the writing in red is the delete button code): print "<table id='mainforum' align='center'>"; print "<tr class='headline'><td width=50%>Feedback comment</td><td width=20%>left by:</td><td>Replies</td><td>Last replied time</td><td>Remove</td></tr>"; $getthreads="SELECT * from forumtutorial_posts where parentid='0' order by lastrepliedto DESC"; $getthreads2=mysql_query($getthreads) or die("Could not get threads"); while($getthreads3=mysql_fetch_array($getthreads2)) { $getthreads3['post']=strip_tags($getthreads3['post']); $getthreads3['author']=strip_tags($getthreads3['author']); print "<tr class='mainrow'> <td><A href='message.php?id=$getthreads3[postid]'> '$getthreads3'</a></td> <td>'$getthreads3[author]'</td><td>$getthreads3[numreplies]</td> <td>'$getthreads3[showtime]'<br>Last post by <b>'$getthreads3[lastposter]'</b></td> <form action='delete.php' method='post'> <td> <input type='submit' value='Delete' /></td> </tr>"; } print "</table>"; print "</form>"; And here is the delete.php code: <?php include("connect.php"); mysql_query("DELETE from forumtutorial_posts where postid = postid"); echo "<td><A href='manage.php'> back</a></td>"; ?> Thanks in advance! Link to comment https://forums.phpfreaks.com/topic/196501-delete-button-to-remove-a-row-from-a-table-and-db/ Share on other sites More sharing options...
litebearer Posted March 25, 2010 Share Posted March 25, 2010 your delete code is effectively saying 'if the id in the database equals the id in the database, delete it'. you need to get the id you are looking for and compare that against the id in the database. Make sense? Link to comment https://forums.phpfreaks.com/topic/196501-delete-button-to-remove-a-row-from-a-table-and-db/#findComment-1031685 Share on other sites More sharing options...
rebecca09 Posted March 25, 2010 Author Share Posted March 25, 2010 Thanks yeh that makes sense. Just a bit confused on what the actual 'id' is that we need. At the moment the query is 'WHERE postid = postid' obviously that isnt correct but do you know what the right 'id' i need to be looking at is, in order to delete the row. Im guessing the 'id' im looking for is in the forum.php file?? Link to comment https://forums.phpfreaks.com/topic/196501-delete-button-to-remove-a-row-from-a-table-and-db/#findComment-1031726 Share on other sites More sharing options...
litebearer Posted March 25, 2010 Share Posted March 25, 2010 ok... when I am writing code, I find it is always helpful to start with 'darn near plain english' pseudo code. In your case. Where do you define which record is the one you want to delete? what factor(s) distinguish that particular record from all the other records? whose actions tell you that particular record needs deleting? Link to comment https://forums.phpfreaks.com/topic/196501-delete-button-to-remove-a-row-from-a-table-and-db/#findComment-1031833 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.