title: Why isn't my delete button working?
body: <p>My code is: (<strong>Edited</strong> after a suggestion from an answer)</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;SomuFinance - Personal Finance Manager&lt;/title&gt;
      &lt;link rel="stylesheet" type="text/css" href="indexStyle.css"&gt;
      &lt;script src="scripts/jquery-3.1.0.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;form method="post" action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;"&gt;
          &lt;div id="container"&gt;
              &lt;input type="submit" class="button" name="edit" value="Edit" /&gt;
              &lt;input type="button" class="button" name="delete" value="Delete" /&gt;
              &lt;input type="text" id="action" name="action"&gt;
              &lt;table id="listDB"&gt;
                  &lt;tr&gt;
                      &lt;th&gt;Select&lt;/th&gt;
                      &lt;th&gt;ID&lt;/th&gt;
                      &lt;th&gt;Category ID&lt;/th&gt;
                      &lt;th&gt;Shop&lt;/th&gt;
                      &lt;th&gt;Item&lt;/th&gt;
                      &lt;th&gt;Quantity&lt;/th&gt;
                      &lt;th&gt;Unit&lt;/th&gt;
                      &lt;th&gt;Price Based On&lt;/th&gt;
                      &lt;th&gt;MRP&lt;/th&gt;
                      &lt;th&gt;Seller's Price&lt;/th&gt;
                      &lt;th&gt;Last Updated On&lt;/th&gt;
                  &lt;/tr&gt;
                  &lt;?php
                      $dbc =  mysqli_connect('localhost','root','atlantis2016','itemDB')
                                  or die("Error Connecting to Database");
  
                      if(isset($_POST['submit']))
                      {
                          echo "Action Set to ".$_POST['action'];
                          if($_POST['action']=='confirmDelete')
                          {
                              echo "Now Deleting!!";
                              foreach ($_POST['selected'] as $delete_id) 
                              {
                                  $query = "DELETE FROM grocery WHERE id = $delete_id";
                                  mysqli_query($dbc, $query)
                                      or die('Error querying database.');
                              }
                          }
                      }
  
                      $query1 = "SELECT DISTINCT category FROM grocery";
                      $result1 = mysqli_query($dbc, $query1)
                                  or die("Error Querying Database");
  
                      while($row = mysqli_fetch_array($result1))
                      {
                          $category = $row['category'];
                          $query2 = "SELECT * FROM grocery WHERE category='$category' ORDER BY item ASC";
                          $result2 = mysqli_query($dbc, $query2)
                                  or die("Error Querying Database");
  
                          echo '&lt;tr&gt;';
                              echo '&lt;td class="catHead" colspan=11&gt;'.$category.'&lt;/td&gt;';
                          echo '&lt;/tr&gt;';
                          $catCount=1;
  
                          while($inRow = mysqli_fetch_array($result2))
                          {
                              $id = $inRow['id'];
                              $shop = $inRow['shop'];
                              $item = $inRow['item'];
                              $qnty = $inRow['quantity'];
                              $unit = $inRow['unit'];
                              $price_based_on = $inRow['price_based_on'];
                              $mrp = $inRow['MRP'];
                              $sellers_price = $inRow['sellers_price'];
                              $last_updated_on = $inRow['last_updated_on'];
  
                              echo '&lt;tr&gt;';
                                  echo '&lt;td&gt;&lt;input type="checkbox" value="' . $id . '" name="selected[]" /&gt;&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$id.'&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$catCount.'&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$shop.'&lt;/td&gt;';
                                  echo '&lt;td class="leftAligned"&gt;'.$item.'&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$qnty.'&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$unit.'&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$price_based_on.'&lt;/td&gt;';
                                  echo '&lt;td class="pri"&gt;₹'.$mrp.'&lt;/td&gt;';
                                  echo '&lt;td class="pri"&gt;₹'.$sellers_price.'&lt;/td&gt;';
                                  echo '&lt;td&gt;'.$last_updated_on.'&lt;/td&gt;';
                              echo '&lt;/tr&gt;';
  
                              $catCount++;
                          }
                      }
  
                      mysqli_close($dbc);
                  ?&gt;
                  &lt;input type="submit" value="Submit"&gt;
              &lt;/table&gt;
          &lt;/div&gt;
  
          &lt;div class="dialogBG"&gt;
              &lt;div id="deleteConfirmDialog" class="dialog"&gt;
                  &lt;div class="closeDialog"&gt;&lt;/div&gt;
                  &lt;p&gt;Sure you want to delete the selected Data?&lt;/p&gt;
                  &lt;input type="submit" id="confirmDelete" class="dialogButton" name="edit" value="Delete" /&gt;
                  &lt;input type="button" class="dialogButton cancelButton" name="delete" value="Cancel" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/form&gt;
      &lt;script type="text/javascript"&gt;
          $(document).ready(function(){
              $('.button').click(function(){
                  if($(this).val()=="Delete")
                  {
                      $(".dialogBG").fadeIn(200);
                      $("#deleteConfirmDialog").show(200);
                      $("#action").val('confirmDelete');
                  }
                  else if($(this).val()=="Edit")
                  {
  
                  }
              });
  
              $('#confirmDelete').click(function(){
                  $(".closeDialog").trigger("click");
              });
              $('#cancelDelete').click(function(){
  
              });
              $(".closeDialog").click(function (e){
                  $(this).parent(".dialog").hide('200').parent(".dialogBG").fadeOut('200');
              });
              $(".cancelButton").click(function (e){
                  $(this).parent(".dialog").hide('200').parent(".dialogBG").fadeOut('200');
              });
              $("form").submit(function(e){
                  alert("Form is being sumbitted!");
              });
          });
      &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I want the elements for which the checkbox is selected, contained in the php array selected[], to be deleted from the database. Before deletion, I want a confirmation dialog box to open up, which will contain the "submit" button. This will cause the actual deletion. However, for some reason the above code doesn't work. I can't even be sure if the post is being submitted, as the line <code>echo "Action Set to ".$_POST['action'];</code> doesn't return any output. Please help.</p>
  
  <p>I believe this entire section of code is not working (from manual testing).</p>
  
  <pre><code>if(isset($_POST['submit']))
      {
          echo "PHP Working here!";
          echo "Action Set to ".$_POST['action'];
          if($_POST['action']=='confirmDelete')
          {
              echo "Now Deleting!!";
              foreach ($_POST['selected'] as $delete_id) 
                  {
                      $query = "DELETE FROM grocery WHERE id = $delete_id";
                      mysqli_query($dbc, $query)
                          or die('Error querying database.');
                  }
          }
      }
  </code></pre>
  
  <p>Any ideas why?</p>