title: Deleting something in a mysqli database with a button?
body: <p>So I'm just making a simple program that puts names into a database. I got that part down, I can enter a name into a form, then display it on the page, but now I'd like to know how to delete them from the database, and no longer show them on the page.</p>
  
  <p>I added a button next to each name that triggers the third if statement (with the commented out query), and from what I can tell it's best to run a query based on the element's id (my primary key that auto increments), but I have no idea how to get the id from the element who's button I'm clicking on.</p>
  
  <p>How do I get the id from one of the elements in my while loop? Or if there's a better way to delete them, what's that? 
      
  
  <pre><code>if (mysqli_connect_errno()) {
  die('could not connect');
  }
  
  if (isset($_POST['first_name'], $_POST['last_name'])){
  $first_name = trim($_POST['first_name']);
  $last_name = trim($_POST['last_name']);
  $putitin = mysqli_query($db, "INSERT INTO names (first_name, last_name) VALUES ('$first_name', '$last_name')");
  }
  
  if (isset($_POST['del'])){
  //$takeitout = mysqli_query($db, "DELETE FROM names WHERE id = ");
  }
  
  ?&gt;
  
  
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  
  &lt;form action='' method='post'&gt;
  &lt;div&gt;
  &lt;label for "first_name"&gt;First name&lt;/label&gt;
  &lt;input type="text" name="first_name"&gt;
  &lt;/div&gt;
  &lt;div&gt;
  &lt;label for "last_name"&gt;Last name&lt;/label&gt;
  &lt;input type="text" name="last_name"&gt;
  &lt;/div&gt;
  &lt;div&gt;
  &lt;input type="submit" value="Insert"&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;hr&gt;
  
  &lt;?php
  $resultset = $db-&gt;query('SELECT * FROM names');
  if($resultset-&gt;num_rows != 0){
  while($rows = $resultset-&gt;fetch_assoc()) {
      $fname = $rows['first_name'];
      $lname = $rows['last_name'];
      $id = $rows['id'];
  
      echo "&lt;form action='' method='post'&gt;&lt;p&gt;Name: $fname $lname $id&lt;input type='submit' name='del'&gt;&lt;/form&gt;&lt;/p&gt;";
  
  }
  } else {
  echo 'No results';
  }
  
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>