title: PHP: Delete || Confirm delete
body: <p>I am having a problem.</p>
  
  <p>I am creating a script that allows a person to select a record by it's primary ID and then delete the row by clicking a confirmation button.</p>
  
  <p>This is the code with the form:
  "confirmdelete.php"</p>
  
  <pre><code>&lt;?php
  include("dbinfo.php");
  $sel_record = $_POST[sel_record];
  
  //SQL statement to select info where the ID is the same as what was just passed in
  $sql = "SELECT * FROM contacts WHERE id = '$sel_record'";
  
  //execute SELECT statement to get the result
  $result = mysql_query($sql, $db) or die (mysql_error());//search dat db
  if (!$result){// if a problem
      echo 'something has gone wrong!';
  }
  else{
      //loop through and get dem records
      while($record = mysql_fetch_array($result)){
          //assign values of fields to var names
          $id = $record['ID'];
          $email = $record['email'];
          $first = $record['first'];
          $last = $record['last'];
          $status = $record['status'];
          $image = $record['image'];
  
          $filename = "images/$image";
  
      }
  
  $pageTitle = "Delete a Monkey";
  include('header.php');
  
  echo &lt;&lt;&lt;HERE
  Are you sure you want to delete this record?&lt;br/&gt;
  It will be permanently removed:&lt;/br&gt;
  &lt;img src="$filename" /&gt;
  &lt;ul&gt;
  &lt;li&gt;ID: $id&lt;/li&gt;
  &lt;li&gt;Name: $first $last&lt;/li&gt;
  &lt;li&gt;E-mail: $email&lt;/li&gt;
  &lt;li&gt;Status: $status&lt;/li&gt;
  &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="really truly delete"/&gt;
  &lt;input type="button" name="cancel" value="cancel" onClick="location.href='index.php'" /&gt;&lt;/a&gt;
  &lt;/p&gt;&lt;/form&gt;
  HERE;
  }//close else
  //when button is clicked takes user back to index
  ?&gt;
  </code></pre>
  
  <p>and here is the reallydelete.php code it calls upon</p>
  
  <pre><code>&lt;?php
  include ("dbinfo.php");
  
  $id = $_POST[id];//get value from confirmdelete.php and assign to ID
  $sql = "SELECT * FROM contacts WHERE id = '$id'";//where primary key is equal to $id (or what was passed in)
  
  $result=mysql_query($sql) or die (mysql_error());
  //get values from DB and display from db before deleting it
  while ($row=mysql_fetch_array($result)){
      $id = $row["id"];
      $email = $row["email"];
      $first= $row["first"];
      $last = $row["last"];
      $status = $row["status"];
  
      include ("header.php");
      //displays here
      echo "&lt;p&gt;$id, $first, $last, $email, $status has been deleted permanently&lt;/p&gt;";
  }
  
  $sql="DELETE FROM contacts WHERE id = '$id'";
  //actually deletes
  $result = mysql_query($sql) or die (mysql_error());
  ?&gt;
  </code></pre>
  
  <p><em><strong>The problem is that it never actually ends up going into the "while" loop</em></strong>
  The connection is absolutely fine.</p>
  
  <p>Any help would be much appreciated.</p>