title: php function call from on button click using jquery/ajax
body: <p>trying to call php function on button click to delete row from db which i'm looping... need to pass button tag id attribute to the function. cant get it work</p>
  
  <pre><code>$('button').click(
      function(){
          var id = $(this).attr('id');
          $.ajax({
              url: "ins.php",
              type: "POST",
              data: id,
              success: function(data){
              }
          });
      });
  
  // html button in table to delete a row
  &lt;td&gt;&lt;button id='.$i.' name="delete"&gt;&lt;img src="delete.png"&gt;&lt;/button&gt;&lt;/td&gt;
  </code></pre>
  
  <hr/>
  
  <pre><code>// ins.php
  if (isset($_POST['delete'])){
      DB_delete($conn, $_POST['delete']); 
  }
  
  // function that deletes the row
  function DB_delete($conn,$id){
  
      $sql = "DELETE FROM person WHERE id = ?";
  
      $stmt=$conn-&gt;prepare($sql);
      $stmt-&gt;bind_param('i',$id);
      $stmt-&gt;execute();
      $stmt-&gt;close();
  }
  </code></pre>