rx3mer Posted September 3, 2009 Share Posted September 3, 2009 Here is my simple question: I started to create my own simple guest-book and I wanted to make it with simple admin page witch is gonna allow me just to delete the comments. I have made the submit form and the view form where all comments are echo-ed. I`ve been looking different tutorials how to delete row`s with check-box and just with click on the comment but non of them works. When i click on any comment aways deletes the last one :| and also when i refresh the page again starts to delete the comments form the last one... Please help! This is the code i made: <html> <body> <p> </p> <table width="200" border="1"> <tr> <td><?php include ".../includes/config.php"; //select database //if cmd has not been initialized if(!isset($cmd)) { //display all $result = mysql_query("select * from $tbl_name order by id"); while($r=mysql_fetch_array($result)) { //grab the title and the ID of the guestbook $comment=$r["comment"];//take out the title $id=$r["id"];//take out the id //make the title a link echo "<a href='delete.php?cmd=delete&id=$id'>$id - Delete</a>"; echo "<br>"; echo "<br>"; } } ?> <? if($_GET["cmd"]=="delete") { $sql = "DELETE FROM $tbl_name WHERE id=$id"; $result = mysql_query($sql); } ?> </td> </tr> </table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/173044-problem-with-deleting-rows-form-mysql-table/ Share on other sites More sharing options...
trq Posted September 3, 2009 Share Posted September 3, 2009 if($_GET["cmd"]=="delete") { $id = mysql_real_escape_string($_GET['id']); $sql = "DELETE FROM $tbl_name WHERE id = $id"; $result = mysql_query($sql); } Link to comment https://forums.phpfreaks.com/topic/173044-problem-with-deleting-rows-form-mysql-table/#findComment-912085 Share on other sites More sharing options...
rx3mer Posted September 4, 2009 Author Share Posted September 4, 2009 You are genius!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! THANK YOU VERY MUCH!!!!!!!! :P :P Link to comment https://forums.phpfreaks.com/topic/173044-problem-with-deleting-rows-form-mysql-table/#findComment-912090 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.