CodeIgniter Forums
$this->input->post() function not working in model for one instance but others its ok? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: $this->input->post() function not working in model for one instance but others its ok? (/showthread.php?tid=43280)

Pages: 1 2


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]brucebat[/eluser]
Hi,

I have checked my syntax, naming and made sure that I have not called the function elsewhere.

But still when I try to input a value from post it comes back null, I have spent the past 3 hours tearing my code up from my view, controller and model and still no luck.

Whats even more confusing, is that my other post functions work fine in the same model so it cannot be a problem with CI.

I tried name changes, etc.

Here is the codes:


This is my array that is passed as a parameter to the pulldown.

Code:
$department = array
                (
                    '1' => 'Cardiology',
                    '2' => 'Radiology'
                );

The pull down function in the view
Code:
echo form_dropdown ('procedure_deparment', $department,set_value('procedure_department'));

The result HTML

Code:
<select name="procedure_deparment">

<option value="1">Cardiology</option>
<option value="2">Radiology</option>
</select>


The post function in my Model:

Code:
//sets the foreign key from dropdown form
$departmentfk = $this->input->post('procedure_department');


The value getting inserted into my database is 0, null which is causing problems. So I really need to fix his.



Thanks


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]ccschmitz[/eluser]
Have you checked to see if the variable $departmentfk is being set to the proper value or if the error is happening with the code that is inserting the record? Could you post the rest of the code from that method in your model?


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]brucebat[/eluser]
ccschmitz

I tried echoing the variable to check it but nothing comes up just a blank page.

Here is the code so far.

Code:
function create_record()
        {
            
            
            //Patient segment
            $patient = array
            (
                'patient_age' =>$this->input->post ('patient_age'),
                'patient_height' => $this->input->post ('patient_height'),
                'patient_weight' => $this->input->post ('patient_weight'),
                'patient_gender' => $this->input->post ('patient_gender')
            );
        
            $insertpatient = $this->db->insert ('patient', $patient);
            
                //To be used as FK in Procedure table
                $patientfk = $this->db->insert_id();
            
            
            //Name of the procedure
            
            $procedurename = array
            (
                'procedure_name' => $this->input->post('procedure_name'),
                //procedure description not implemented yet!
                'procedure_description' => 'NULL'
                
            );
            
            $insertprocedurename = $this->db->insert('procedure_name', $procedurename);
            
                //To be used as FK in Procedure table
                $procedurenamefk = $this->db->insert_id();
            echo $procedurename;
            //Procedure department
            
                //Does not require inserting a new record, just using a FK value to an existing record e.g. 1= Cardiology , 2= Radiology
            
                $departmentfk = $this->input->post('procedure_department');
                
                echo $departmentfk;
                return;
                
            //Patient Dosage
            
                    //If no dosage dosage FK = NULL
                    
                        if ( ! $this->input->post('dosage'))
                        {
                            $dosagefk = NULL;
                        
                        }
                    
                        else
                        {
                            //To be implemented
                        
                        
                        }
                        
            //Procedure
            
                $proceduredata = array
                (
                    'patient_id' => $patientfk,
                    'name_id' => $procedurenamefk,
                    'department_id' => $departmentfk,
                    'dosage_id' => $dosagefk,
                    'edocument' => NULL, //not implemented yet
                    'user_id' => $this->session->userdata('userID'),
                    'duration' => NULL, //not implemented yet
                    'submitted' => date('d-m-Y H:i:s', now()),
                    'comment' => NULL, //to be implemented
                
                );
            
                $insertprocedure = $this->db->insert('procedure', $proceduredata); //inserts into 'procedure' table with $proceduredata array
                $procedurefk = $this->db->insert_id(); //gets the primary key of the row inserted
            
            
            
            //Staff
            
                    
                        
            //



$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]brucebat[/eluser]
Here is a picture of my database as well

http://i.imgur.com/D1M4J.png


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]Caio[/eluser]
could be a spelling mistake
Notice that 'procedure_deparment' != 'procedure_department'


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]mi6crazyheart[/eluser]
I think the 3rd parameter in u'r following code may b creating d prob...
Code:
echo form_dropdown ('procedure_deparment', $department, set_value('procedure_department'));

Just, remove that 3rd parameter & test once...


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]ccschmitz[/eluser]
[quote author="mi6crazyheart" date="1309983472"]I think the 3rd parameter in u'r following code may b creating d prob...
Code:
echo form_dropdown ('procedure_deparment', $department, set_value('procedure_department'));

Just, remove that 3rd parameter & test once...[/quote]

Yeah, set_value doesn't work with dropdowns. There is a set_select method you could try though: http://ellislab.com/codeigniter/user-guide/helpers/form_helper.html


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]brucebat[/eluser]
Wow I feel really stupid.

Thankyou everyone and especially Caio for spotting my spelling mistake 'procedure_deparment'

I dont think I will be able to live this one down, haha!


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]Caio[/eluser]
[quote author="brucebat" date="1309983715"]Wow I feel really stupid.

Thankyou everyone and especially Caio for spotting my spelling mistake 'procedure_deparment'

I dont think I will be able to live this one down, haha![/quote]

No prob mate. it happens to the very best developers. hehehe


$this->input->post() function not working in model for one instance but others its ok? - El Forum - 07-06-2011

[eluser]Armchair Samurai[/eluser]
[quote author="ccschmitz" date="1309983702"]Yeah, set_value doesn't work with dropdowns. [/quote]

Actually, set_value() works perfectly fine with form_dropdown().