dean7 Posted December 5, 2009 Share Posted December 5, 2009 Hi all, On my website ive got a forum, which im trying to code somthing for it so you can delete the topic but im not sure how to do this.. Ive tryed many ways but its deleted all the topics not just the one. This is part of my forum code where im trying to make the button so they can delete it: <td align="center" bgcolor="#FFFFFF"><?php echo $rows['datetime']; ?></td> <td align="center" bgcolor="#FFFFFF">***<a href="delete.php?delete=delete&id=$id">Delete</a>*** </td> </tr> And this is my delete.php file: <?php session_start(); include ("main_forum.php"); include ("includes/config.php"); if ($_GET['delete']){ $sql = "DELETE FROM forum_question WHERE id=$id"; $result = mysql_query($sql); echo "Topic Deleted!"; ?> Anyone know a way that i can delete topics without delete every one of them? Thanks for your help:) Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 5, 2009 Share Posted December 5, 2009 DELETE FROM forum_question WHERE id='$id' you forgot to put single quote is that what you need?? Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2009 Author Share Posted December 5, 2009 Nope, because its still not deleting that row. Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 5, 2009 Share Posted December 5, 2009 if($_GET['delete']=="delete"){ check this one Quote Link to comment Share on other sites More sharing options...
graham23s Posted December 5, 2009 Share Posted December 5, 2009 Hi Buddy, You don't seem to be passing the id through to the delete file, if ($_GET['delete']){ this checks if you want to delete the file, but then we need the id to tell mysql to delete. if you put: $id = $_GET['id']; in the delete file to that should work Graham Quote Link to comment Share on other sites More sharing options...
robert_gsfame Posted December 5, 2009 Share Posted December 5, 2009 THat's Right you haven't get the value from the url $_GET['id'] Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2009 Author Share Posted December 5, 2009 It echo's topic deleted but it actually isnt.. Its still showing there :S Quote Link to comment Share on other sites More sharing options...
graham23s Posted December 5, 2009 Share Posted December 5, 2009 Hi Mate, That will always say "Topic Deleted" because it's next in line to execute to find out if it's really deleted do: <?php if ($sql) // Thgis checks if the delete was successful (true) else (false) { print "Topic Deleted"; } else { print "An error occured deleting the topic!"; } ?> When you hover your cursor over: <a href="delete.php?delete=delete&id=$id">Delete</a>*** do you see the ID in the bottom left window in explorer? Graham Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2009 Author Share Posted December 5, 2009 It echoed "topic deleted" while it still didnt delete. Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 5, 2009 Share Posted December 5, 2009 It echoed "topic deleted" while it still didnt delete. Its still showing there :S Why are you echoing the row of 'datetime', when you're deleting a forum_questions row in your SQL statement? Quote Link to comment Share on other sites More sharing options...
gergy008 Posted December 5, 2009 Share Posted December 5, 2009 Did no-one spot this? <td align="center" bgcolor="#FFFFFF"><?php echo $rows['datetime']; ?></td> <td align="center" bgcolor="#FFFFFF"><?php echo("<a href=\"delete.php?delete=delete&id=".$id."\">Delete</a>"); ?> </td> </tr> Quote Link to comment Share on other sites More sharing options...
oni-kun Posted December 5, 2009 Share Posted December 5, 2009 Oh! The $id was not in <?php tags. I guess it was just a simple mistake, atleast we helped him with other things. Quote Link to comment Share on other sites More sharing options...
gergy008 Posted December 5, 2009 Share Posted December 5, 2009 Oh! The $id was not in <?php tags. I guess it was just a simple mistake, atleast we helped him with other things. Wow, Epic, I spotted a problem ^^ Quote Link to comment Share on other sites More sharing options...
dean7 Posted December 5, 2009 Author Share Posted December 5, 2009 Ive changed them things but it isnt delete the topic still... The url i have is: delete.php?delete=delete&id= Quote Link to comment Share on other sites More sharing options...
graham23s Posted December 5, 2009 Share Posted December 5, 2009 If the id is blank like you are showing: delete.php?delete=delete&id= there is a problem retieving the data from the database, better show your whole code Graham Quote Link to comment 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.