title: Use Delete Button to Delete Record from Database
body: <p>I have a database containing books. On a page, I have loop that prints each record in the database which each book's title, author, publisher, date, and rating. I want to use a delete button at the bottom of each record in order to delete it. </p>
  
  <p>When I click on the delete button, the page is updated, but the record is not deleted.</p>
  
  <p>I have tried to find solutions to this problem, but have yet to. I tried to use the book_id category in my database table as my index, in order to identify each record and delete it but it does not work.</p>
  
  <p>Here is the code for my button form, as it appears with html code:</p>
  
  <pre><code> while ($row = mysqli_fetch_array($result)) 
   {
  
   echo '&lt;div id="forminput"&gt;';
  
  $timestamp = strtotime($row['date']);
  
  echo '&lt;div id = "bookpicture"&gt;';
  echo '&lt;img src="images/Book Cover 8crop.jpg" alt="Book Cover"&gt;';
  echo '&lt;/div&gt;';
  
  echo '&lt;div id = "bookinfo"&gt;';
  echo '&lt;div id = "titleauthor"&gt;';
  echo '&lt;h3&gt;' . htmlspecialchars($row['title'], ENT_QUOTES, 'UTF-8') . '&lt;/h3&gt;';
  echo '&lt;p&gt;' . htmlspecialchars($row['author'], ENT_QUOTES, 'UTF-8') . '&lt;/p&gt;';
  
  echo '&lt;/div&gt;';
  echo '&lt;/div&gt;';
  
  $id = htmlspecialchars($row['book_id'], ENT_QUOTES, 'UTF-8');
  
  echo '&lt;/div&gt;' ;
  echo '&lt;div id = "publisher"&gt;' ;
  echo '&lt;p&gt;' . 'Published on' . " " . htmlspecialchars(date('F j, Y,', $timestamp),    
  ENT_QUOTES, 'UTF-8') . 
  " " . 'by' . " " . htmlspecialchars($row['publisher'], ENT_QUOTES, 'UTF-8') . '&lt;/p&gt;';
  echo '&lt;/div&gt;';
  echo '&lt;div id = "formDelete"&gt;';
  echo '&lt;form name="deleteForm" method="post" id="deleteForm" action="index.php"&gt;'; 
  echo '&lt;input type="submit" value="Update" name="myAdd" id="myAdd" style = "width:  
  100px" required&gt;';
  echo '&lt;input type="submit" value="Delete" name="myDelete" id="$id" style = "width: 
  100px" required&gt;';
  echo '&lt;/form&gt;';
  echo '&lt;/div&gt;';
  echo '&lt;/div&gt;';
  echo '&lt;hr&gt;' ;
  
  echo '&lt;/div&gt;';
  }
  ?&gt; 
  </code></pre>
  
  <p>Here is the code from my index.php file.</p>
  
  <pre><code>else if (isset($_POST['myDelete']))
  {
  $ids = mysqli_real_escape_string($link, $_POST['$id']);    
  
  $sql="DELETE FROM readbooks WHERE book_id = '$ids'";
  
  if (!mysqli_query($link, $sql))   
  
  {   
  
  $error = 'Error with submission: ' . mysqli_error($link);   
  
  include 'php/error.html.php'; 
  
  exit();   
  
    } 
  }
  </code></pre>
  
  <p>Here is the updated code.</p>