title: Attempting to insert new row into database using PDO
body: <p>Ok, so I've been trying to do this for days, and I've been reading all sorts of tutorials, but I seem to be missing something, because I still can't get it. I'm working on learning about web forms and inserting the form input into the respective database. I'm able to take the info from the form and echo it on the result page, so I know that all works. but I can't seem to get the form input to go into my database. I know the connection works, so there must be something wrong with my syntax. </p>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>//DB Configs
      $username = null;
      $password = null;
  
      try {
          $db = new PDO("mysql:host=localhost;dbname=Testing3", $username, $password);
          //Set the PDO error mode to exception (what does this mean?)
          $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
          //Prepare SQL and bind parameters
          $sql = $db-&gt;prepare("INSERT INTO `NFK_SPECIES` (`Name`)
              VALUES (:name)");
  
          //Insert a Row
          $species = $_POST['Species'];
          $sql-&gt;execute(array(':name'=&gt;$species));
  
      }
      catch (PDOException $e) {
          echo "Error: " . $e-&gt;getMessage();
      }
      $result = $db-&gt;query('SELECT * from `NFK_Species` ORDER BY `Id` DESC');
      //Query
      /*
      $input = $db-&gt;query("INSERT INTO `NFK_Species` (`Id`, `Name`) VALUES (Null, `$species`)");
  
      $result = $db-&gt;query('SELECT * from `NFK_Species` ORDER BY `Id` DESC');*/
  
      //Kill Connection
      $db = Null;
  }
  </code></pre>
  
  <p><strong>HTML/PHP (web page)</strong></p>
  
  <pre><code>&lt;h1&gt;Inserting a New Species into Database:&lt;/h1&gt;
      &lt;h3&gt;Results&lt;/h3&gt;
      &lt;?php
      if ($sql-&gt;execute()){
          echo "Data input was successful";
          while ($rows = $result-&gt;fetch()){
              echo $rows['Name']; echo ", ";
          }
      } else {
          echo "Data input failed."; echo mysql_error();
  
      }
      ?&gt;
  </code></pre>
  
  <p>This is only my current attempt at doing this. I prefer the attempt I had before, with the <code>bindParam</code> and simple <code>execute()</code>, so if I could get that to work instead, I'd appreciate it. The following example also has the <code>Id</code> column for this table. This is an auto-increment column, which I read doesn't need to be included, so I excluded it from my recent attempt. Is that correct?</p>
  
  <p><strong>Past PHP</strong></p>
  
  <pre><code>//Prepare SQL and bind parameters
          $sql = $db-&gt;prepare("INSERT INTO `NFK_SPECIES` (`Id`, `Name`)
              VALUES (Null, :name)");
          $sql-&gt;bindParam(':name', $species);
  
          //Insert a Row
          $species = $_POST['Species'];
          $sql-&gt;execute();
  </code></pre>
  
  <p>I've been reading a bunch of tutorials (or trying to), including attempting to decipher the php.net tutorials, but they all seem to be written for people who already have a good handle on this and experience with what's going on, and I'm very new to all of this. </p>