![]() |
Inserting form fields into a database - 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: Inserting form fields into a database (/showthread.php?tid=30533) |
Inserting form fields into a database - El Forum - 05-18-2010 [eluser]bcarter[/eluser] Hi there Yet another noob question I'm afraid.... Can someone tell me if there is a snippet of code I can use to insert multiple $_POST values into a database instead of declaring each one? I'll try and show you what I mean. Currently I am using the below code Code: $insert = array( This works fine however there are actually 56 fields. Is there some code that I can use that would put all the values from the form fields into the $insert array? Thanks for your help! Inserting form fields into a database - El Forum - 05-18-2010 [eluser]Clifford James[/eluser] try using this in your input fields: Code: <input name="question[]" /> Code: <input name="question[0]" /> Then with codeigniter $this->input->post('question') is the array you want. Inserting form fields into a database - El Forum - 03-25-2011 [eluser]Unknown[/eluser] If your variables from the View, match the Database columns, you can insert the whole $_POST. Given, that your insert function in the model has ability to take Array. Inserting form fields into a database - El Forum - 05-19-2011 [eluser]strike312[/eluser] I am doing the same thing and I have the form fields the same as the columns in the database. I seem to be getting a problem, the 'submit' is being taken as a column and therefore causing issues. This is the error: Quote:Error Number: 1054 And this is the code in the model: Code: $insert= $this->db->insert($dest,$this->input->post()); And the code in the view: Code: echo form_input('Q1','Question 1'); Inserting form fields into a database - El Forum - 05-19-2011 [eluser]strike312[/eluser] Ah i managed to solve the error, it seems if i change the form_submit code line to this: Code: echo form_submit('','Submit'); Now it works, but is this the best thing to do I am wondering? Leaving the submit name as '', will that have a side effect somewhere else? Thanks. Inserting form fields into a database - El Forum - 05-20-2011 [eluser]bcarter[/eluser] Is there really a need to include submit in the database? |