Jump to content

Problem with deleting row`s form mysql table


rx3mer

Recommended Posts

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...  :shrug::wtf:

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>

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.