title: How to pass data from post to ajax in codeigniter
body: <p>So i have table and trying to do C.R.U.D.</p>
  
  <p>I make for edit form with modal. As my table populate inside of foreach i put my modal inside in table to get correct id of row.</p>
  
  <p>This is my ajax function</p>
  
  <pre><code> $("#uin").click(function(){
  var mydata = $("form#update-interview").serialize();
  var id = $("#jsonid").val();
  console.log(mydata); // it's only for test
  
      $.ajax({
          type: "POST",
          url: "vacancy/interview/" + id , //process
          data: { user_submission_token: $("#session_token").val(),mydata },
          dataType: "json",            
                      success: function(msg){
              alert("Succeess");
              $("#form-content").modal('hide'); //hide popup  
          },
          error: function(){
              alert("failure");
          }
      });
  });
  </code></pre>
  
  <p>From this Ajax Submit im getting output like:</p>
  
  <pre><code>candidate_id=120&amp;vacancy_id=48&amp;stage=Interview&amp;date=&amp;candidate_id=120&amp;vacancy_id=49&amp;stage=Interview&amp;date=&amp;candidate_id=120&amp;vacancy_id=53&amp;stage=Interview&amp;date=&amp;candidate_id=120&amp;vacancy_id=54&amp;stage=Interview&amp;date=&amp;candidate_id=120
  </code></pre>
  
  <p>and this continues until last ID, so i need to get only 1 candidate_id ,vacancy_id and stage with date.</p>
  
  <p>Its getting all of them because is inside in foreach but if i put my form outside of foreach then how i will get my row ID?</p>
  
  <p>this is my function in controller</p>
  
  <pre><code> public function interview($i) 
  
      {
          $type=$this-&gt;input-&gt;post();
      $test=  json_encode($data= array(
              "status" =&gt; 1,
              "candidate_id" =&gt; $this-&gt;input-&gt;post('candidate_id'),
              "vacancy_id" =&gt; $this-&gt;input-&gt;post('vacancy_id'),
              "date" =&gt; $this-&gt;input-&gt;post('date'),
              "stage" =&gt; $type[3],
          )
      );
      var_dump($test);
              die();
          $this-&gt;vacancies-&gt;update_interview($data, array("vacancy_id" =&gt; $i));
  
      }
  </code></pre>
  
  <p>from this controller var_dump i got this output <code>{"status":1,"candidate_id":false,"vacancy_id":false,"date":false,"stage":null}</code></p>
  
  <p>seems my function is not correct also, can i get some advice?</p>
  
  <p>and model side is just this</p>
  
  <pre><code>    public function update_interview($i) 
  {       
      $this-&gt;db-&gt;insert("interviews", $i);
  }
  </code></pre>
  
  <p>For any case this is my form its little-bit long</p>
  
  <pre><code>                     &lt;!-- Update  Interview--&gt;
     &lt;div id="myModal" class="modal fade" role="dialog"&gt;
    &lt;div class="modal-dialog"&gt;
  
      &lt;!-- Modal content--&gt;
  
      &lt;form class="no-error-margin" id="update-interview"&gt;
      &lt;div class="modal-content"&gt;
        &lt;div class="modal-body"&gt;
     &lt;div class="form-group"&gt;
                 &lt;input type="hidden" name='candidate_id' value="&lt;?= $candidate_id; ?&gt;" /&gt;
                 &lt;input type="hidden" name='vacancy_id' id="jsonid" value="&lt;?= $row['id']; ?&gt;" /&gt;
  
     &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
          &lt;label class="control-label"&gt;Type:&lt;/label&gt;
              &lt;select id="classinput" tabindex="1" name="stage" class="form-control required"&gt;
                    &lt;option value="Interview"&gt;Interview&lt;/option&gt;
                    &lt;option value="Final Interview"&gt;Final Interview&lt;/option&gt;
                    &lt;option value=""&gt;Rejected&lt;/option&gt;
              &lt;/select&gt;
           &lt;/div&gt;    
               &lt;!-- Using DatePicker--&gt;
  
          &lt;div class="date-form"&gt;
          &lt;div class="control-group"&gt;
          &lt;label class="control-label" style="margin: 0 30%;padding: 7px;"&gt;When The Interview Will Be?&lt;/label&gt;
      &lt;div class="container"&gt;
      &lt;div class="row"&gt;
          &lt;div class='col-sm-6 col-md-offset-3'&gt;
              &lt;div class="form-group"&gt;
                  &lt;div class='input-group date' id='datetimepicker1'&gt;
                      &lt;input name="date" type='text' class="form-control" /&gt;
                      &lt;span class="input-group-addon"&gt;
                          &lt;span class="glyphicon glyphicon-calendar"&gt;&lt;/span&gt;
                      &lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;/div&gt;
          &lt;/div&gt;   
        &lt;/div&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="modal-footer"&gt;
    &lt;button id="uin" type="submit" data-dismiss="modal" class="btn btn-warning btn-lg" style="width: 100%;"&gt;&lt;span class="glyphicon glyphicon-ok-sign"&gt;&lt;/span&gt; Update&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  &lt;?php   echo   form_close();?&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  &lt;!-- End  Interview--&gt; 
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Okay thanks to <strong><em>Niranjan N Raju</em></strong></p>
  
  <p>Now i'm getting just 1 result in POST and its correct which is looks like</p>
  
  <pre><code>candidate_id=126&amp;vacancy_id=46&amp;stage=Interview&amp;date=12/03/2015+12:00+AM
  </code></pre>
  
  <p>So now how to insert this into database? Into candidate_id , vacancy_id , stage and date columns with their values?</p>