I'm doing an insert to a table, some data is empty so I expect some fields to get the default value I assigned.
$data = array(
'id' => $id,
'user' => $this->input->post('name'),
);
$this->the_model->the_model_funciton($data);
The problem is with the user field, the default value for the field is 'Anon' but when there's no data in the post('name') an empty value is inserted instead of the default value in the field.
User field is varchar, null.
Would this do it?
$data = array(
'id' => $id
);
if ($user = $this->input->post('name')) {
$data['user'] = $user;
}
This is probably related to the post method. When name is empty or undefined it will return an empty string. Which then gets input in the column.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With