![]() |
Radio button - 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: Radio button (/showthread.php?tid=55679) Pages:
1
2
|
Radio button - El Forum - 11-06-2012 [eluser]hujan[/eluser] hi all, I'm new in CodeIgniter and I need help on my radio button..the problem is it did not recorded/inserted into the database. below are my code on the radio button area. at the view script: Code: <p> at my model: Code: $data = array( 'sap_yes'=>$this->input->post('sap_yes'), please help me..being stuck at this part for the whole day already. Radio button - El Forum - 11-06-2012 [eluser]Rabbel[/eluser] He hujan, shouldn't you use the name selectors instead of the values? Code: $data = $this->input->post('sap_radio1'); And if you still have problems, you should try to 'debug' your code a bit. Like putting echo's everywhere. You can try this to see what your code does after submitting values: Code: echo $this->input->post('sap_radio1'); Radio button - El Forum - 11-06-2012 [eluser]noslen1[/eluser] You have to fill with field name inside $this->input->post(), not value. The method $this->input->post() will return to you the value. So you should write... Code: $data = array('sap'=>$this->input->post('sap_radio1')) ... and it will store $data['sap'] = "sap_yes" or $data['sap'] = "sap_no" according to what radio button has been clicked. Radio button - El Forum - 11-06-2012 [eluser]hujan[/eluser] this is in the view part Code: <p> Code: $data = array('sap_yes'=>$this->input->post('sap_yes'), my sap_yes, sap_no, sponser and my_sponser are the fields that i used inside the sap table.and the data type that is use is tinyint(2).. Radio button - El Forum - 11-06-2012 [eluser]Rabbel[/eluser] Hujan, in this case there will never be a post value 'sap_yes' and 'sap_no'. The identifiers will be the values of the NAME of your radiobuttons: 'sap_radio1' and 'sap_radio2'. You should do this in your model class: Code: $data = array('sap_radio1'=>$this->input->post('sap_radio1'), Radio button - El Forum - 11-06-2012 [eluser]hujan[/eluser] Code: $data = array('sap_yes'=>$this->input->post('sapradio1'), is this what you mean? Radio button - El Forum - 11-06-2012 [eluser]Rabbel[/eluser] Nope, you need to select your two names of your radio button groups: sap_radio1 and sap_radio2.. Radio button - El Forum - 11-06-2012 [eluser]hujan[/eluser] i have tried Code: $data = array('sap_radio1'=>$this->input->post('sap_radio1'), but it give me this error Code: Array ( [sap_radio1] => sap_no [sap_radio2] => ) Radio button - El Forum - 11-06-2012 [eluser]Rabbel[/eluser] The error you see there is an error where you try to put values in your database. Above the error you see the result of the print_r output: Code: Array ( [sap_radio1] => sap_no [sap_radio2] => ) Now you should use the values in this array to put in your database. The error you get says you do not have a column sap_radio1 in your sap table. Radio button - El Forum - 11-06-2012 [eluser]noslen1[/eluser] [quote author="hujan" date="1352205447"] my sap_yes, sap_no, sponser and my_sponser are the fields that i used inside the sap table.and the data type that is use is tinyint(2)..[/quote] You mean you have in your database 2 fields called "sap_yes" and "sap_no" ? If that's the case, I think you should have just one field called something like "sap" that will be set to TRUE or FALSE, or 1 or 0. I dont get the logic here... |