php - CodeIgniter - how to post value from form as NULL instead of 0 -


in database table: tab_companies , column company_phone (big integer) defalut value set null.

when fill form , leave phone number field empty code igniter should add null value database, instead having value '0'.

public function add_company() {     $data = array(         'company_short-name'        => $this->input->post('company_short-name'),         'company_full-name'         => $this->input->post('company_full-name'),         'company_phone'             => $this->input->post('company_phone'),         'company_address'           => $this->input->post('company_address'),     );      return $this->db->insert('tab_companies', $data);    } 

what doing wrong?

you do, set null in case empty, like:

$company_phone = $this->input->post('company_phone');  ... 'company_phone'  => (!empty($company_phone)) ? $company_phone : null, ... 

Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -