If statement and empty string to DB

Your code doesn’t seem to be malformed, so I imagine the if statement is being evaluated correctly.

It’s possible to place restrictions on DB column types, along with default values and whether that field is allowed to be null. I’ll assume you’re using a MySQL database here, in which case you can run the following query to get some information about your table schema:

DESCRIBE halbForm;

The resulting output will give you information regarding the column types and rules regarding records in that table. That might lead you to the answer to your question about empty strings. FWIW, it is perfectly acceptable to store an empty string a database field.

Looking at the code though, I wonder which path is being executed. When you are having the issue with the record not being saved to the database, are you catching your PDOException and echoing out your error message on your error.html.php page? If this is the case, you could get some more helpful information from the PDOException:

catch (PDOException $e)
{
    print_r($e); // Add this line
    $error = 'Error inserting into halbForm';
    include 'error.html.php';
    exit();
}

Warning - Shameless plug for my github project following:

You may also want to perform some more analysis on your query, which can be troublesome using PDO’s prepared statements. If you’ve exhausted your other troubleshooting steps and would like to see an example of what the query being executed actually looks like, you can try using this project to simulate that query: