title: Delete Row from DB using PHP/MYSQL
body: <p>I am trying to delete my data row from my MySQL db.</p>
  
  <p>Below is the query which prints the result of a table with keywords in them. See this pic to see how my results show up: <img src="https://i.stack.imgur.com/YO6OF.png" alt="enter image description here"></p>
  
  <p>I am successfully able to get my data from my addKeywordTable however, I can not get the deletion to take place. Here is my index.php page which shows the input button that gets clicked to activate the deletion: </p>
  
  <pre><code> &lt;?php
   include 'db.php'; 
  
   $sql = mysqli_query($con,"SELECT * FROM addKeywordTable ORDER BY 
   Keyword_Name ASC");
  
   print &lt;&lt;&lt;HERE
   &lt;table id="home"&gt;
   HERE;
  
   while ($row = mysqli_fetch_array($sql))
   {
   $key = $row['Keyword_Name'];
  
   print &lt;&lt;&lt;HERE
   &lt;tr&gt;&lt;td&gt;
   &lt;form method="post" formenctype="multipart/form-data" formmethod="POST" 
        value="Delete"      action="deleteKey.php"&gt;
   &lt;tr&gt;
   &lt;input type="hidden" name="sel_key" value="$id"&gt;
   &lt;input type="submit" name="delete" value=" Delete " id="deleteKey" &gt; $key
   &lt;hr/&gt;&lt;/tr&gt;
   &lt;/form&gt;&lt;/td&gt;&lt;/tr&gt;
       HERE;
   }
       print "&lt;/tr&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;";
    ?&gt;
  </code></pre>
  
  <p>When you click the "Delete" button, you are taken to the confirm page deleteKey.php which looks like this:</p>
  
  <pre><code>        &lt;?php
  
      require 'db.php';
      $sel_key = $_POST[sel_key];
  
      //SQL statement to select information
      $sql = "SELECT * FROM addKeywordTable WHERE keyID = $sel_key";
  
      //loop through record and get values
      while ($key = mysqli_fetch_array($result)) {
      $id = $key['Keyword_Name'];
      } // end while loop
  
      $pageTitle = "Delete a Keyword";
  
      print &lt;&lt;&lt;HERE
      &lt;div id="form1profile"&gt;
      &lt;h2&gt;Are you sure you want to delete this record?&lt;br/&gt;
      It will be permanently removed:&lt;/h2&gt;
  
      &lt;ul&gt;
      &lt;li&gt;Keyword Category:&lt;br/&gt;&lt;/li&gt;
      $key;
      &lt;/ul&gt;
      &lt;p&gt;&lt;br /&gt;
      &lt;form method="post" action="reallyDelete.php"&gt;
      &lt;input type="hidden" name="id" value="$id"&gt;
      &lt;input type="submit" name="reallydelete" value="Confirm Delete" /&gt;
      &lt;input type="button" name="cancel" value="cancel"
      onClick="location.href='addProfile.php'" /&gt;&lt;/a&gt;
      &lt;/p&gt;&lt;/form&gt;&lt;/div&gt;
      HERE;
      // close else
  
      ?&gt;
  </code></pre>
  
  <p>and after you confirm the deletion, you are then taken to confirm page: "reallyDelete.php". This is the page I am having trouble with. For some reason, my variable does not display the contents of the row/keyword name.</p>
  
  <p>My DB only has 2 columns in it: KeyID and Keyword_Name</p>
  
  <p>here is the delete confirmation page. How could I pass the $id to the db to delete the keyword/record.</p>
  
  <pre><code>  &lt;?php
        include 'db.php';
  
    $id = $_POST[id];
    $sql = "SELECT * FROM addKeywordTable WHERE Keyword_Name = '$id'";
  
    while ($row = mysqli_fetch_array($result)) {
    $id = $row['Keyword_Name'];
         } // end while loop
  
    print "&lt;p&gt; $row has been permanently deleted.&lt;/p&gt;";
  
  
    $sql="DELETE FROM addKeywordTable WHERE Keyword_Name = '$id'";
    echo "&lt;meta http-equiv='Refresh' content='2; URL=addKeyword.php'&gt;";
    ?&gt;
  </code></pre>
  
  <p>Any help with this would be great.Below is a screenshot of my sql table for addKeywordTable</p>
  
  <p><img src="https://i.stack.imgur.com/SWg4t.png" alt="SQL DB"></p>