title: Delete button after every post (php, sql)
body: <p>I need some help with PHP and SQL. Im doing a website where you can post notes in different subjects (Work, Home, School, and so on). After every note that being selected from my database I want a button that can delete that specific post when it's not needed anymore. I can make it delete but is deletes wrong note, always the one above or below. I don't know whats wrong with my code? Please help me.   </p>
  
  <pre><code>    &lt;?php 
      $query = "SELECT * FROM notes WHERE subject='Work' order by id desc";
      $result = mysql_query($query);
      while ($row = mysql_fetch_array($result)) { 
              $id = $row['id'];
              $subject = $row['subject'];
              $date = $row['date'];
              $note = $row['note']; 
  
              print "&lt;p&gt;&lt;strong&gt;$subject&lt;/strong&gt; ($id), $date &lt;/p&gt;"; 
              print "&lt;p&gt; $note &lt;/p&gt;";
  
          ?&gt;
          //delete button starts here here
          &lt;form id="delete" method="post" action=""&gt;
          &lt;input type="submit" name="delete" value="Delete!"/&gt;    
          &lt;?php
          if(isset($_POST['delete'])){
             $query = "DELETE FROM notes WHERE id=$id"; 
             $result = mysql_query($query);
          }
          ?&gt;  
          &lt;/form&gt;
          &lt;?php
      }   
      ?&gt;
  </code></pre>
  
  <p>And when I press delete I get this:</p>
  
  <blockquote>
    <p>Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/mirho663/www-pub/webbpage/menu2.php on line 40</p>
  </blockquote>
  
  <p>What does that mean and how do I fix it?  </p>