Unable to post space to database: postgreSQL and Codeigniter

I have an empty input on my browse page, but whenever I have to publish to my database, it gets an error.

Pageview:

<label for="column1">COLUMN1:</label> 
<input type="input" name="column1">

Model Page:

 'column1' => $this->input->post('column1'),

This code will not satisfy if my input is empty. How can I send it to my database with a value of 0 instead of empty (because it will not be satisfactory).

Column1 is an integer type, so an empty value is not an integer, as I understand it. Can someone help me.

BTW I use Codeigniter and PostgreSQL

EDIT ------- MY REAL CODE

Model

 public function changeNow_table2_A(){
 $seq = $this->input->post('seq');
 $data = array(

   'tech_voc' => $this->input->post('tech_voc'),
   'bacc' => $this->input->post('bacc'),
   'post_bacc' => $this->input->post('post_bacc'),
   'llb' => $this->input->post('llb'),
   'md' => $this->input->post('md')

 );

   $this->db->where('seq', $seq);
   $this->db->update('table2', $data); 
 } // this work

I tried to change only

'bacc' => empty($this->input->post('bacc'))? 0 : $this->input->post('bacc'),
    // changing 'bacc' to this, it gets server error.
+4
source share
2 answers

, - , .

$column1 = $this->input->post('column1');
$data = array('testcol' => 'testing',
          'column1' => (empty($column1) || !is_numeric($column1)) ? 0 : $column1);

column1 0, 1 1


5.5 empty . empty($this->input->post('field')) . PHP 5.5 empty. , , empty. php, .

php empty

+1

.

'column1' => empty($this->input->post('column1'))? 0 : $this->input->post('column1'),
0

Source: https://habr.com/ru/post/1529618/


All Articles