Can't post blank to database: postgreSQL and Codeigniter
Not sure if you resolved this yet - just in case, here is another answer.
$column1 = $this->input->post('column1');$data = array('testcol' => 'testing', 'column1' => (empty($column1) || !is_numeric($column1)) ? 0 : $column1);
This will set column1
to 0 if column1 is empty or if column1 is not a number
Prior to version 5.5 the empty
function only supports variables. Meaning empty($this->input->post('field'))
will throw a fatal error. PHP 5.5 included support for using expressions as arguments to empty
. The error was most likely a result of using a function as an argument to the empty
function. Check your version of php to confirm this.
here is the php empty documentation
You could make use of a ternary operator.
'column1' => empty($this->input->post('column1'))? 0 : $this->input->post('column1'),