title: Inserting empty variables into MySQL with PDO prepared statement
body: <p>I'm banging my head against a wall, trying to work out why this PDO prepared statement isn't working. The only thing I can conclude is that if a variable is empty, the INSERT fails, but this is confusing because I must've done this a thousand times before without issue.</p>
  
  <p>Here's my code. All of the variables are being set from an POST variable, so some of them could be blank if the user didn't provide this data.</p>
  
  <pre><code>$stmt = $db-&gt;prepare("INSERT INTO students
      (id, classid, userid, firstname, surname, form, gender)
      VALUES ('', :classid, :userid, :firstname, :surname, :form, :gender)");
  
      $stmt-&gt;execute(array(':userid' =&gt; $userid, ':classid' =&gt; $classid, ':firstname' =&gt; $firstname, ':surname' =&gt; $surname, ':form' =&gt; $form, ':gender' =&gt; $gender));
  </code></pre>
  
  <p>Is there some way of telling it to insert an empty  field if the variable is empty?</p>
  
  <p>EDIT: To be clear, this is not a new statement. I had previously been INSERTing with unprepared MySQLi, and had only just got around to updating this bit of code to PDO.</p>
  
  <p>EDIT 2: My schema:</p>
  
  <pre><code>id  int(11) NO  PRI     auto_increment  
  encryption  int(1)  NO              
  classid int(11) NO              
  googleclassroom varchar(50) NO              
  userid  varchar(50) NO              
  firstname   varchar(100)    NO              
  surname varchar(100)    NO              
  form    varchar(10) NO              
  gender  varchar(10) NO              
  colour_code varchar(10) NO              
  col1    varchar(50) NO              
  col2    varchar(50) NO              
  col3    varchar(50) NO              
  col4    varchar(50) NO              
  col5    varchar(50) NO              
  col6    varchar(50) NO              
  col7    varchar(50) NO              
  timestamp   datetime    NO  
  </code></pre>