title: PDO Insert not working
body: <p>I'm trying to take a record from one table in my database and place it in another table (as a backup of the data - needs to be kept for 7 years, including deleted data). The select works, the delete works, but the insert doesn't.
  What's wrong? What can I do to fix it?</p>
  
  <p>Code:</p>
  
  <pre><code>////////// DELETE STUDENT RECORD /////////
  ///// step 1 - copy all data to exStudentInfo with removal date //////
  
  $studentID = $_REQUEST['sID'];
  // pull student data from the database //
  $query = "SELECT * FROM studentinfo WHERE studentID=" . $studentID;
  $statement = $db-&gt;prepare($query);
  $statement -&gt;execute();
  while($row = $statement-&gt;fetchObject())
      {
          $studentFirst = $row-&gt;studentFirst;
          $studentLast = $row-&gt;studentLast;
          $studentDOB = $row-&gt;studentDOB;
          $studentGrade = $row-&gt;studentGrade;
          $studentClass = $row-&gt;studentClass;
          $studentAllergy = $row-&gt;studentAllergy;
          $studentFam = $row-&gt;studentFam;
          $removeDate = date("Y-m-d");
      }
  </code></pre>
  
  <p>SOLVED: The problem is in $query... I've used ordinary apostrophes (') rather than the correct backtick (`) - and I'd forgotten to include the photo field in the bound values.</p>
  
  <pre><code>$query = "INSERT INTO 'sundayschool'.'exstudentinfo' ('studentID' ,'studentFirst' ,'studentLast' ,'famID' ,'studentDOB' ,'studentGrade' ,'studentClass' ,'studentAllergy' ,'studentPhoto' ,'removeDate') VALUES (:id, :first, :last, :fam, :dob, :grade, :class, :allergy, :date)";
  </code></pre>
  
  <p>Correct form:</p>
  
  <pre><code>$query = "INSERT INTO `sundayschool`.`exstudentinfo` (`studentID` ,`studentFirst` ,`studentLast` ,`famID` ,`studentDOB` ,`studentGrade` ,`studentClass` ,`studentAllergy` ,`studentPhoto` ,`removeDate`) VALUES (:id, :first, :last, :fam, :dob, :grade, :class, :allergy,:photo,:date)";
  $statement = $db-&gt;prepare($query);
  $statement-&gt;bindValue(':id',$studentID, PDO::PARAM_INT);
  $statement-&gt;bindValue(':first',$studentFirst, PDO::PARAM_STR);
  $statement-&gt;bindValue(':last',$studentLast, PDO::PARAM_STR);
  $statement-&gt;bindValue(':fam',$studentFam, PDO::PARAM_INT);
  $statement-&gt;bindValue(':dob',$studentDOB, PDO::PARAM_STR);
  $statement-&gt;bindValue(':grade',$studentGrade, PDO::PARAM_STR);
  $statement-&gt;bindValue(':class',$studentClass, PDO::PARAM_STR);
  $statement-&gt;bindValue(':allergy',$studentAllergy, PDO::PARAM_STR);
  $statement-&gt;bindValue(':date',$removeDate, PDO::PARAM_STR);
  $statement-&gt;execute();
  
  ///// step 2 - Delete student from studentinfo table //////
  $stmt = $db-&gt;prepare("DELETE FROM studentinfo WHERE studentID=:id");
  $stmt-&gt;bindValue(':id', $studentID);
  $stmt-&gt;execute();
  echo $studentFirst . " " . $studentLast . " has been removed from the system (and backed up)";
  echo "&lt;p&gt;&lt;a href='admin.php'&gt;&amp;lt;&amp;lt; Return to administration page&lt;/a&gt;&lt;/p&gt;";
  </code></pre>