title: PDO MySQL inserting twice each time?
body: <p>Each time I fill the form, the system inserting the data twice to the table?
  Why is that happening?</p>
  
  <pre><code>// This checks if variabes are not empty, and if username is less than 11 characters long.
  if (!empty($username) &amp;&amp; !empty($password) &amp;&amp; !empty($message) &amp;&amp; strlen($username) &lt; 11) {
  
      // Shortcut for our ID generator function.
      $ID = generateID();
  
      // Now lets insert (register the account) these datas to our database.
      $insert = $connect-&gt;prepare(
      "INSERT INTO users ( 
          username, 
          password, 
          message, 
          `date`, 
          `time`, 
          id
      ) VALUES ( 
          :username, 
          :password, 
          :message, 
          CURDATE(), 
          CURTIME(), 
          :id 
      )");
  
      // Executing in array, because if we binded all these variables, it would look very bad.
      $insert-&gt;execute(array(
          ':username' =&gt; $username,       
          ':password' =&gt; $password, 
          ':message' =&gt; $message, 
          ':id' =&gt; $ID
      ));
  
      if (!$insert-&gt;execute()) {
          print_r($insert-&gt;errorInfo());
      }       
  }
  // Let's check if errors is not empty.
  else if (!empty($errors)) 
  {
      // Now let's use a loop to get all of the error messages set in the array.
      foreach ($errors as $error) {
          echo $error;
      }
  }
  </code></pre>
  
  <p>I am pretty new to PDO, this is my first time I've done a PDO connection, execute, query.
  I don't see anything wrong there?
  Thanks.</p>
  
  <p>Generate ID function</p>
  
  <pre><code>    $nums = substr(hash('sha512', '123456789'), 0, 20);
      $ID = str_shuffle($nums);
      return $ID;
  </code></pre>
  
  <p>HandleErrors function</p>
  
  <pre><code>function handleErrors() {
      // Create new array to handle errors
      $errors = array();
  
      // Setting our errors
  
      // If username is empty, set error.
      if (empty($username)) {
          $errors[] = 'Username is empty';
      } 
      // If password is empty, set error.
      else if (empty($password)) 
      {
          $errors[] = 'Password is empty';
      } 
      // If username length is more than 11, set error.
      else if (strlen($username) &gt; 11)
      {
          $errors[] = 'Your username is more than 11 characters long';
      }
  }
  </code></pre>
  
  <p>Misc:</p>
  
  <pre><code>&lt;?php
  require('inc/config.inc.php');
  require('inc/session.inc.php');
  include('inc/functions.inc.php');
  ?&gt;
  
  &lt;html&gt;
  &lt;h1&gt;Recover&lt;/h1&gt;
  &lt;br /&gt;
  
  
  &lt;form action="recover.php" method="POST"&gt;
      Your name: &lt;input type="text" name="username"&gt;&lt;br /&gt;
      Password for this recover: &lt;input type="password" name="password"&gt;&lt;br /&gt;
      Your Message: &lt;input type="text" name="message"&gt;&lt;br /&gt;
      &lt;input type="submit" name="submit"&gt;&lt;br /&gt;
  &lt;/form&gt;
  
  &lt;?php
      // Check if isset, also fixes the php notices error.
      if (isset($_POST['username']) &amp;&amp; isset($_POST['password']) &amp;&amp; isset($_POST['message'])) {
          // Created shortcuts for the POSTs we currently have.
          $username = $_POST['username'];
          $password = $_POST['password'];
          $message = $_POST['message'];
      }
  
      // Let's call our error handling function from functions.inc.php - before we doing the checking.
  
      handleErrors();
  </code></pre>