title: Delete row from database with an image and a value that is a primary key
body: <p>I got this code to show a table on my webpage. The content of the table is linked with a database. So I get the table from the database in a html table. At the end of each (html) row, I got an image (icon-delete.png). This gets the value of the <code>$row[0]</code> (this is where my PKID is, so it's always a unique number and it's an auto ascend. Now I want to clear the individual row where I click on the icon-delete.png button with PHP code. The row has to be deleted from the database also. This is my code at this moment:</p>
  
  <pre><code>$con = mysql_connect('localhost', 'root', '');
  if ($con) {
      mysql_select_db('bieren', $con);
      $result = mysql_query('SELECT * FROM brouwers');
      echo '&lt;form action="" method="post"&gt;';
      echo '&lt;table border="0" cellspacing=0&gt;';    
      echo '&lt;tr class="heads"&gt;
          &lt;th&gt;brouwernr&lt;/th&gt;
          &lt;th&gt;brouwernaam&lt;/th&gt;
          &lt;th&gt;adres&lt;/th&gt;
          &lt;th&gt;postcode&lt;/th&gt;
          &lt;th&gt;gemeente&lt;/th&gt;
          &lt;th&gt;omzet&lt;/th&gt;
      &lt;/tr&gt;';
  
      $counter = 0;
      while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
          if($counter % 2 == 0){
              echo '&lt;tr class="even"&gt;';
          } else{
              echo '&lt;tr class="oneven"&gt;';
          }
  
          for($i = 0; $i &lt;=6; $i++){
              $counter ++;
              echo '&lt;td&gt;';
              echo $row[$i];
              echo'&lt;/td&gt;';
          }
  
          echo '&lt;td&gt; &lt;input type="image" src="icon-delete.png" name="delete" value ="'.$row[0].'" /&gt; &lt;/td&gt;';
          echo '&lt;/tr&gt;';
      }   
  } else {
      echo 'Connectie niet geslaagd. Reden: ' . mysql_error() . '. Probeer opnieuw.';
  }
  echo '&lt;/table&gt;';
  echo '&lt;/form&gt;';
  
  if(isset($_POST))
  {
      $con = mysql_connect('localhost', 'root', '');
  
      if ($con) {
          mysql_select_db('bieren', $con);
          $result = mysql_query('DELETE FROM brouwers 
                    WHERE brouwers.brouwernr = "'.$row[0].'"');}
  }
  </code></pre>
  
  <p>One of the last rules of my code says: WHERE <code>brouwers.brouwernr = $row[0]</code> but this is not the correct row to delete. I'll also show an image of what I got now in html so you can understand what it has to do:</p>
  
  <p><img src="https://i.stack.imgur.com/VkekZ.png" alt="The webpage view"></p>