CodeIgniter Forums
Null from controller to model - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Null from controller to model (/showthread.php?tid=75201)



Null from controller to model - pippuccio76 - 01-10-2020

hi , sorry for english , how can i insert null  in db passing the value from controller to model ?

Controller (ajax) : 
Code:
  function change_step()
  {

    $id_cotta              = $this->input->post('id_cotta');
   
    if ( $this->input->post('data_fine_conteggio') == 'NULL') {
   
      $data_fine_conteggio   = NULL;

    } else {

      $data_fine_conteggio   = $this->input->post('data_fine_conteggio');       
    }
   
    $numero_step_conteggio = $this->input->post('numero_step_conteggio');
    $pausa                 = $this->input->post('pausa');



    $res = $this->cotte_model->cambia_step(
                                            $id_cotta,
                                            $data_fine_conteggio,
                                            $numero_step_conteggio,
                                            $pausa

                                          );

    if($res){

      return true;
    }

   
  }

Model :


Code:
  public function cambia_step(
                                $id_cotte,
                                $data_fine_conteggio,
                                $numero_step_conteggio,
                                $pausa=NULL
                             ){

        // update record  into database


        $data = array(

                      'data_fine_conteggio' => $data_fine_conteggio,
                      'numero_step_conteggio' => $numero_step_conteggio,
                      'pausa' => $pausa
                    );

       $this->db->where('id', $id_cotte);



        if($this->db->update('cotte', $data)){

            return TRUE;

        }else{

            return FALSE;

        }


  }

But if i set NULL on ajax post the field in db don't change ...


RE: Null from controller to model - php_rocs - 01-10-2020

@pippuccio76,

Are you sure that your database field accepts NULL values? Are you seeing any errors? If so, what are they? Why don't you kick out the generated query to see what it looks like when a NULL value is given.


RE: Null from controller to model - pippuccio76 - 01-10-2020

(01-10-2020, 11:24 AM)php_rocs Wrote: @pippuccio76,

Are you sure that your database field accepts NULL values?  Are you seeing any errors?  If so, what are they?  Why don't you kick out the generated query to see what it looks like when a NULL value is given.

My db accept null values , i don't see any error and cannot generate the last  query because i call it with ajax  ...


RE: Null from controller to model - jreklund - 01-10-2020

You can, but you will need to open up the "Network" tab, look for "XHR". And then you can see the response.


RE: Null from controller to model - pippuccio76 - 01-10-2020

(01-10-2020, 12:58 PM)jreklund Wrote: You can, but you will need to open up the "Network" tab, look for "XHR". And then you can see the response.

"The request has no response data available"  ... but other field are change only data don' change


RE: Null from controller to model - jreklund - 01-10-2020

You will need to add the code for last query and exit; or die; so you can see that query in that window. If you wanted to check that.