title: Delete specific entry from database by clicking on it
body: <p>I'm building a web App for a friend, this is my first async site and I'm learning lots of cool stuff, but there are some details that make me struggle.</p>
  
  <p>This is the general idea:</p>
  
  <p>This simple app gets specific tables from a database using PHP and jQuery and shows them asynchronously on the page. There's this specific table (a waitlist) that shows all atributes from all entries on the table plus a small button that SHOULD delete that specific entry, the PHP code for the creation of the table is as follows:</p>
  
  <pre><code>&lt;?php
  include("con.php");
  $result = mysqli_query($c,"SELECT * FROM waitlist");
  echo "&lt;thead&gt;";
  echo "&lt;tr&gt;";
  echo "&lt;th&gt;Nombre&lt;/th&gt;&lt;th&gt;Sillas&lt;/th&gt;&lt;th&gt;Hora de Llegada&lt;/th&gt;";
  echo "&lt;/tr&gt;";
  echo "&lt;/thead&gt;";
  echo "&lt;tbody&gt;";
  while ($places = mysqli_fetch_array($result)) {
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;". $places ['NAME']."&lt;/td&gt;";
      echo "&lt;td&gt;". $places ['CHAIRS']."&lt;/td&gt;";
      echo "&lt;td&gt;". $places ['CREATED']."&lt;/td&gt;";
          echo '&lt;td&gt;
                    &lt;button class="btn btn-default" type="submit" name=' . $places ['ID'] . ' id="deleteWaitlist"&gt;X&lt;/button&gt;
               &lt;/td&gt;';
      echo "&lt;/tr&gt;";
  }
  echo "&lt;/tbody&gt;";
  mysqli_free_result($result);
  ?&gt;
  </code></pre>
  
  <p>This is the table schema:</p>
  
  <pre><code>CREATE TABLE WAITLIST (
      ID MEDIUMINT NOT NULL AUTO_INCREMENT,
      NAME VARCHAR(255),
      CHAIRS VARCHAR(255),
      CREATED DATETIME NOT NULL,
      PRIMARY KEY(ID)
  )ENGINE=InnoDB DEFAULT CHARSET=utf8;
  </code></pre>
  
  <p>What is the best way of having the button delete the entry it apears on? The function refreshes the table every few seconds so deleting it from the database is all I need. I also have an incomplete PHP function that gets called on buttonpress that shold delete the entry, but Im unsure as to how to complete it. Here it is:</p>
  
  <pre><code>&lt;?php
   include("con.php");    
   $sql = "DELETE FROM waitlist WHERE id='.$_POST[id]'.";
   mysqli_query($c,$sql);
  ?&gt;
  </code></pre>
  
  <p>I need to replace the $_POST[name] with an identifier for the row, this is my problem. What's the best way of doing this? Can I pass it somehow though the jquery.ajax() call? Do I need a new table attribute ID? I'm sure the "this" keyword can be used somewhere. Is PHP and ajax even the best way of doing it?</p>
  
  <p>Ajax writes the table on "#result_table", here's the relevant code if it's needed:</p>
  
  <pre><code>&lt;div class="row"&gt;
          &lt;div class="col-lg-12" id="table_container"&gt;
              &lt;table class="table table-striped" id="result_table"&gt;
  
              &lt;/table&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>EDIT: I updated the code as recomended by @vnponce</p>
  
  <p>This is the code for the ajax call:</p>
  
  <pre><code>$("#deleteWaitlist").click(function(){
      // Get the varible name, to send to your php
      var i = $(this).attr('name');
      $.post({
          url: 'deleteWaitlist.php', 
          data: { id : i},
          success: function(result){
              // do some code here
              // here yo can see 'result' response of YOUR_PHP_FILE
              console.log(result);
          }
      });
  });
  </code></pre>
  
  <p>After fiddling with the code I got rid of all errors and updated the post, but the entries are still not getting deleted.</p>