Remove post method and initialize for each loop in php codeigniter -


i want remove input->post @ line $attain = $this->input->post('mytext', true); .itried many ways errors display. how can rid of post method?

$attain = $this->input->post('mytext', true);         $data2=array(); //<-initialize             foreach ($attain $i => $a) { // need index match other properties                 //append array                 $data2[] = array(                 'mytext' => $a,                 'projectname'=> $this->input->post('projectname'),             );             //for multiple entry in same table             $this->db->insert_batch('projectem', $data2);           //}     } 

this view user produce dynamic inputs

    </script>     <script type="text/javascript">     $(document).ready(function() {         var max_fields      = 10; //maximum input boxes allowed         var wrapper         = $(".input_fields_wrap"); //fields wrapper         var add_button      = $(".add_field_button"); //add button id          var x = 1; //initlal text box count         $(add_button).click(function(e){ //on add input button click             e.preventdefault();             if(x < max_fields){ //max input box allowed                 x++; //text box increment                 $(wrapper).append('</br><div><input class="input form-control"" name="mytext[]"/><a href="#" class="remove_field">remove</a></div>'); //add input box             }         });          $(wrapper).on("click",".remove_field", function(e){ //user click on remove text             e.preventdefault(); $(this).parent('div').remove(); x--;         })     });     </script>  <div class="input_fields_wrap">                     <div class="form-group">                     <button type="button" class="btn btn-success add_field_button">add more fields</button>                      </div>                  </div> 

this how 3values save in database enter image description here

from comments above think trouble same data inserting multiple times. if case,

i think u missed closing bracket .try $this->db->insert_batch('projectem', $data2); outside loop

$attain = $this->input->post('mytext', true); $data2 = array(); //<-initialize  foreach($attain $i => $a) {       $data2[] = array(       'mytext' => $a,       'projectname' => $this->input->post('projectname') ,     );  }  // modification here   /*   * if insert_batch inside loop, insert   * occur multiple times   */     $this->db->insert_batch('projectem', $data2); 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -