title: Insert a datetime with prepared statement
body: <p>I am trying to use prepared statements to insert a datetime for a library application. Here is the code thus far:</p>
  
  <pre><code>    global $dbh;
      $query = "INSERT INTO `loan` SET
               `title` = (?), //example value - Lord of the Rings
               `description` = (?), //example value - Trilogy
               `start_date` = (?), //example value 20120701 in String datatype
               `end_date` = (?)";  //example value 20120702 in String datatype
  
      $statement = $dbh-&gt;prepare($query);
      $statement-&gt;bind_param("ssss", $title,$description,$startDate,$endDate);
  
      $statement-&gt;execute();
      print $statement-&gt;error; //to check errors
      $statement-&gt;close();
  </code></pre>
  
  <p>However, I cannot seem to insert this value into the row. At the same time, somehow the</p>
  
  <pre><code>            print $statement-&gt;error 
  </code></pre>
  
  <p>does not seem to display any error.</p>
  
  <p>Any help will really do. </p>
  
  <p>UPDATE:</p>
  
  <p>It actually works. I was just referencing the wrong database. But I want to add a little outro for new people who chanced upon this.</p>
  
  <ol>
  <li><p>Remove all the comments as mentioned in the comments/answers as they will mess up your string.</p></li>
  <li><p>For DATETIME, remember to specify the datatype as String as MySQL only recognises String datatype. If you are not using prepared queries, this means you have to add '' quotes for the values.</p></li>
  <li><p>The insertion will result in the date (2012-07-01 00:00:00) format as time is not specified.</p></li>
  <li><p>Both SQL queries work. INSERT INTO tbl_name SET col_name = value or INSERT INTO tbl_name(col_name) VALUES (value) work.</p></li>
  </ol>