Search code examples
phpcodeignitercodeigniter-2

Codeigniter isset() with or condition not working in multiple parameters


$viewdata['branch']= $this->input->post('branch'); 
if (isset($viewdata['branch']) || isset($viewdata['address']) || isset($viewdata['timings']) || isset($viewdata['clinic']) || isset($viewdata['latitude']) || isset($viewdata['longitude']) || isset($viewdata['image'])) {
    //print_r($viewdata);exit;
    $logid = $this->Adminmodel->Insertdata("table", $viewdata);
}

Why isset() condition is not working with Or. It is directly inserting into table. What should I do?


Solution

  • In php, $something = isset($_POST['something']) ? $_POST['something'] : NULL; With CodeIgniter’s built in methods you can simply do this: $something = $this->input->post('something');

    // Example
    $input = $this->input->post('input_name');
    

    $input will be input_name's value if input_name's value is set.

    $input will be NULL if input_name's value is set.

    So when you checking isset() again on $input. Definately, the value is set and it is null.

    Reference Codeigniter Input Class