title: Codeigniter insert array into database
body: <p>I am currently making a registration form where in you could register individually or by many I need a way how to make the multiple register work i cant add the input into db i get an array to string conversion error
  i still dont have the model for this</p>
  
  <p>my code is
  controller</p>
  
  <pre><code>public function registerbatch(){
              for ($i = 0; $i &lt; count($this-&gt;input-&gt;post('surname','firstname','age','school','course','email')); $i++) {
                  $this-&gt;form_validation-&gt;set_rules("surname[$i]", "surname[$i]", "required");
                  $this-&gt;form_validation-&gt;set_rules("firstname[$i]", "firstname[$i]", "required");
                  $this-&gt;form_validation-&gt;set_rules("age[$i]", "Age[$i]", "required");
                  $this-&gt;form_validation-&gt;set_rules("school[$i]", "School[$i]", "required");
                  $this-&gt;form_validation-&gt;set_rules("course[$i]", "Course[$i]", "required");
                  $this-&gt;form_validation-&gt;set_rules("email[$i]", "Email[$i]", "required");
              }
              if ($this-&gt;form_validation-&gt;run() == TRUE) {
  
                  $reg_dat = array(
  
                      'surname' =&gt; $this-&gt;input-&gt;post('surname'),
                      'name' =&gt; $this-&gt;input-&gt;post('firstname'),
                      'age' =&gt; $this-&gt;input-&gt;post('age'),
                      'school' =&gt; $this-&gt;input-&gt;post('school'),
                      'course' =&gt; ($this-&gt;input-&gt;post('course')),
                      'email' =&gt; ($this-&gt;input-&gt;post('email')),
  
                  );
               $this-&gt;user_model-&gt;add_user($reg_dat);
               $this-&gt;load-&gt;view('user/home_view');
              } else {
                  $this-&gt;load-&gt;view('user/batch_register');
              }
  </code></pre>
  
  <p>view:</p>
  
  <pre><code>&lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt; 
  &lt;body&gt;  
      &lt;form class="form" action="&lt;?php echo base_url() . 'user/registerbatch'; ?&gt;" method="post" class="form-horizontal" role="form"&gt;
  
  
          &lt;?php for ($i = 0; $i &lt; $num; $i++): ?&gt;
          &lt;br&gt;
          Surname: &lt;input type="text" name="surname[]"&gt;
          &lt;br&gt;
          Name: &lt;input type="text" name="firstname[]"&gt;
          &lt;br&gt;
          Age:&lt;input type ="int" name ="age[]"&gt;
          &lt;br&gt;
          School: &lt;input type="text" readonly value="&lt;?= $school ?&gt;" name="school[]"&gt;
          &lt;br&gt;
          Course:&lt;input type ="text" name ="course[]"&gt;
          &lt;br&gt;
          Email:&lt;input type ="text" name ="email[]"&gt;
          &lt;br&gt;
          &lt;br&gt;
  
  
      &lt;?php endfor ?&gt;
     &lt;button type="submit" class="btn btn-success"&gt;Register&lt;/button&gt;
  
  
  &lt;/body&gt;
  &lt;/html&gt; 
  </code></pre>