title: Using PDO to insert data into database
body: <p>I'm trying to use PDO to insert data into my database but I'm getting the error "0 results". I already used PDO to select data from my database but this is the first time I use it to insert data so any help with the below code would be appreciated!   </p>
  
  <p><strong>My form:</strong></p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;form name="blog post" action="insert.php" method="post"&gt;
  
  &lt;label for "id"&gt;Id: &lt;/label&gt;
  &lt;input type="text" name="id"&gt;
  &lt;br&gt;    
  &lt;label for "title"&gt;Title: &lt;/label&gt;
  &lt;input type="text" name="title"&gt;
  &lt;br&gt;    
  &lt;label for "year"&gt;Year: &lt;/label&gt;
  &lt;input type="text" name="year"&gt;
  &lt;br&gt;    
  &lt;label for "text"&gt;Text: &lt;/label&gt;
  &lt;textarea rows="10" cols="50" name="text"&gt;&lt;/textarea&gt;
  &lt;br&gt;    
  &lt;button type="submit"&gt;Submit&lt;/button&gt;
  &lt;/form&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>My insert.php code:</strong></p>
  
  <pre><code>&lt;?php
  
  $pdo = new PDO('mysql:host=localhost;dbname=dbexample', 'userexample', 'paswexample', array(\PDO::MYSQL_ATTR_INIT_COMMAND =&gt;"SET NAMES utf8;SET time_zone = 'Europe/London'"));
  
  $sql = "INSERT INTO `tableexample` (id, title, year, text)
                                          VALUES (:id, :title, :year, :text)";
  $stmt = $pdo-&gt;prepare($sql);
  $stmt-&gt;bindParam(":id", $id);
  $stmt-&gt;bindParam(":title", $title);
  $stmt-&gt;bindParam(":year", $year);
  $stmt-&gt;bindParam(":text", $text);
  
  $form = $_POST;
  $id = $form[ 'id' ];                    
  $title= $form[ 'title' ];                   
  $year= $form[ 'year' ];                 
  $text= $form[ 'text' ];                 
  
  
  $stmt-&gt;execute();
  
  $result = $stmt-&gt;execute(array(':id'=&gt;$id, ':title'=&gt;$title, ':year'=&gt;$year, ':text'=&gt;$text));
  
  if($result) {
      echo "Your text has been posted";
  
      }// end if
  else {
      echo '0 results';
      }// end else
  
  ?&gt;
  </code></pre>