Welcome Guest, Not a member yet? Register   Sign In
Not sure why this won't work
#1

[eluser]Todlerone[/eluser]
Hello all and TY in advance. The $treat_MRI errors on me.

Code:
function add_treatment($ptID, $user, $trtnum){
           $locate = $this->input->post('laterality')." ".$this->input->post('treat_location');
        
        $treat_MRI = (!empty($this->input->post('treat_MRI'))) ? $this->input->post('treat_MRI') : 'NULL';

        $data = array(
            'demo_NumID' => $ptID,
            'treat_num' => $trtnum+1,
            'treat_unit' => $this->input->post('treat_unit'),
            'treat_region' => $this->input->post('treat_region'),
            'treat_location' => $locate,
            'treat_dose' => $this->input->post('treat_dose'),
            'treat_fractions' => $this->input->post('treat_fractions'),
            'treat_MRI' => $treat_MRI,
            'treat_CT' => $this->input->post('treat_CT'),
            'treat_RFV' => $this->input->post('treat_RFV'),
            'treat_VD' => $this->input->post('treat_VD'),
            'treat_PD' => $this->input->post('treat_PD'),
            'treat_DELI' => $this->input->post('treat_DELI'),
            'treat_AUTH' => $this->input->post('treat_AUTH'),
            'treat_START' => $this->input->post('treat_START'),
            'treat_notes' => $this->input->post('treat_notes'),
            'treat_created_on' => unix_to_human(now(), TRUE, 'us'),
            'treat_created_by' => $user['username']);
        
             $this->db->insert('treatments', $data);
        }

TY
#2

[eluser]WanWizard[/eluser]
Showing us the error message might help.

My guess: empty() is a language construct, you can't use it on the return value of a method.

Use this instead:
Code:
// post() returns FALSE if the variable doesn't exist
$treat_MRI = $this->input->post('treat_MRI');

$data = array(
     'demo_NumID' => $ptID,
     'treat_num' => $trtnum+1,
     'treat_unit' => $this->input->post('treat_unit'),
     'treat_region' => $this->input->post('treat_region'),
     'treat_location' => $locate,
     'treat_dose' => $this->input->post('treat_dose'),
     'treat_fractions' => $this->input->post('treat_fractions'),
     'treat_MRI' => $treat_MRI === FALSE ? NULL : $treat_MRI,
     'treat_CT' => $this->input->post('treat_CT'),
     'treat_RFV' => $this->input->post('treat_RFV'),
     'treat_VD' => $this->input->post('treat_VD'),
     'treat_PD' => $this->input->post('treat_PD'),
     'treat_DELI' => $this->input->post('treat_DELI'),
     'treat_AUTH' => $this->input->post('treat_AUTH'),
     'treat_START' => $this->input->post('treat_START'),
     'treat_notes' => $this->input->post('treat_notes'),
     'treat_created_on' => unix_to_human(now(), TRUE, 'us'),
     'treat_created_by' => $user['username']);
        
$this->db->insert('treatments', $data);
#3

[eluser]Todlerone[/eluser]
TY for your response WanWizard. That worked great. I had to slightly change the NULL to "0000-00-00". Even if I set the MySql table to default NULL for the fields I want to be NULL when the form is used and the fields are left blank the table fields get set to 0000-00-00. So I changed the NULL value to check for 0000-00-00.

Cheers




Theme © iAndrew 2016 - Forum software by © MyBB