I am having issues with adding null values to my database via db_insert.
Here is my insert code:
db_set_active('global');
db_insert('contact')->fields(array(
'domain' => global_get_domain(),
'name' => $form_state['values']['name'],
'email' => $form_state['values']['email'],
'phone' => $form_state['values']['phone'],
'state' => $form_state['values']['state'],
'amount' => $form_state['values']['amount'],
'message' => $form_state['values']['message'],
'uri' => $_SERVER['REQUEST_URI'],
'referer' => $_SERVER['HTTP_REFERER'],
'hostname' => $_SERVER['REMOTE_ADDR'],
'timestamp' => time(),
))->execute();
db_set_active();
I am pulling values from my form, but if one of those values was not entered by the user it will not be inserted into my database using db_insert. For instance if $form_state['values']['state'] is null I will receive the error:
PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'state' cannot be null: INSERT INTO {tools_contact} ...
If this variable has a value everything works correctly.