title: Deleting a row with Php & MySQL
body: <p>I am new to php and SQL and just toying around with a project for my own understanding of accessing, updating and deleting data from my Database.</p>
  
  <p>I have managed to show the selected data, create a button to delete a specific Id but really needing some assistance with deleting the selected row or record instead of hard coding in the ID in my delete php script.</p>
  
  <p>Here is an example of my script:</p>
  
  <pre><code>&lt;?php
  
      $sql = "SELECT id, firstname, lastname, joinDate FROM customers";
      $result = $conn-&gt;query($sql);
  
      if ($result-&gt;num_rows &gt; 0) {
          // output data of each row
  
          while($row =  $result-&gt;fetch_assoc()) {
              echo 
                  "&lt;div class='trow'&gt;" . 
                  $row["id"]. ": " . 
                  $row["firstname"] . " " . 
                  $row["lastname"]. " " . 
                  $row["joinDate"]. " " . 
                  "&lt;span class='deleteMember'&gt;
                      &lt;form action='deleteMember.php' method='POST'&gt;
                          &lt;button type='submit'&gt;Delete&lt;/button&gt;
                      &lt;/form&gt;
                  &lt;/span&gt;" . " " . 
                  "&lt;span class='editMember'&gt;&lt;a href='#'&gt;Edit&lt;/a&gt;&lt;/span&gt;" . 
                  "&lt;br&gt;&lt;/div&gt;";
          }
  
      } else {
          echo "0 results";
      }
  
      $conn-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>Here is the delete.php</p>
  
  <pre><code>&lt;?php
  
      // sql to delete a record
      $sql = "DELETE FROM customers WHERE id='6' ";
  
      if ($conn-&gt;query($sql) === TRUE) {
         header("Location: index.php");
      } else {
          echo "Error deleting record: " . $conn-&gt;error;
      }
  
      $conn-&gt;close();
  
  ?&gt;
  </code></pre>
  
  <p>what I would like it to do is, delete the row from which you hit the delete button from and not just delete the row I have specified in the delete.php script. I understand HOW it should work by posting the id but not sure how to do it.</p>