title: Same configuration but one brings: Error SQLSTATE[23000] column cannot be null
body: <p>I know there are already tons of posts concerning this error and I do know how and why it occured. My problem is, that I am using the same configuration and I am running almost identical codes, but only one page brings the error, after the form has been sent. The corresponding columns in the database have exactly the same configuration: Null is off (so actually both have to respond with an error) and the type is varchar, both on autoincrement. I don't know, if it really helps to post the code fragments here, I just hope someone knows/already had a similar occurence with this error. </p>
  
  <p>Now here is the first code for the insert command and the form, which brings no error after it is sent. I have a dropdown button for selecting a subject2, which can also just be left untouched (I shortened the form):</p>
  
  <pre><code>&lt;form name="lfb" action="lfb.php#lfbjump" method="post"&gt;
  
  &lt;select name="subject2"&gt;
  &lt;option value=""&gt;choose another subject&lt;/option&gt;
  &lt;?php foreach ($subjects-&gt;fetchAll() as $subject): ?&gt;
    &lt;option value="&lt;?php echo $subject['fach_id']; ?&gt;"&gt;&lt;?php echo $subject['subject']; ?&gt;&lt;/option&gt;
  &lt;?php endforeach; ?&gt;
  &lt;/select&gt;
  
  &lt;/form&gt;
  </code></pre>
  
  <p>The corresponding insert command (shortened):</p>
  
  <pre><code>$order =  "
  INSERT INTO $dbname.$tablename (
  
  subject2)
  
  VALUES (
  
  :subject2)";
  
  try {
  $pdo = new PDO($dsn, $user, $pw);
  $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch(PDOException $e) {
  echo 'ERROR: ' . $e-&gt;getMessage();
  }
  
  $statement = $pdo-&gt;prepare($order);
  
  $statement-&gt;bindParam(':subject2', $subject2);
  
  
  $subject2 = $_POST['subject2'];
  
  $statement-&gt;execute();
  </code></pre>
  
  <p>And now the other dropdown, which is loaded via ajax (does this make a difference?) and which brings the error:</p>
  
  <pre><code>&lt;select name="noteniveau1"&gt;
    &lt;option value=""&gt;please choose&lt;/option&gt;
    &lt;option value="1"&gt;example 1&lt;/option&gt;
    &lt;option value="2"&gt;example 2&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>The insert commmand (it is in a loop -> $nr goes from 1 to 4).:</p>
  
  <pre><code>$order =  "
  INSERT INTO $dbname.$tablename (
  
  noteniveau)
  
  VALUES (
  
  :noteniveau)";
  
  
  try {
  $pdo = new PDO($dsn, $user, $pw);
  $pdo-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  } catch(PDOException $e) {
  echo 'ERROR: ' . $e-&gt;getMessage();
  }
  
  $statement = $pdo-&gt;prepare($order);
  
  
  $statement-&gt;bindParam(':noteniveau', $noteniveau);
  
  $noteniveau = $_POST["noteniveau$nr"];
  
  $statement-&gt;execute();
  </code></pre>
  
  <p>And the error:</p>
  
  <pre><code>Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]:
  Integrity constraint violation: 1048 Column 'noteniveau' cannot be null' in /var/www/xx/html/xx/xx.php:199 
  Stack trace: #0 /var/www/xx/html/xx/xx.php(199): PDOStatement-&gt;execute() 
  #1 /var/www/xx/html/xx/xx.php(438): include('/var/www/xx...') #2 {main} thrown in /var/www/xx/html/xx/xx.php on line 199
  </code></pre>