title: How to upload file and insert data with php jquery ajax
body: <p>I cannot send via ajax to php file upload and data with ajax. <code>This my code just send file upload</code>. data not send to my php code. I create form and the function send on click using ajax to post on php. <code>I'm using codeigniter</code></p>
  
  <p>This my form:</p>
  
  <pre><code>&lt;form action="&lt;?php echo site_url('home/send_chat');?&gt;" method="post" enctype="multipart/form-data"&gt;
    &lt;input name="message" id="message" type="text" class="form-control input-sm" /&gt;
    &lt;input type="file" id="file" name="file" /&gt;
    &lt;br /&gt;
    &lt;span class="input-group btn"&gt;
      &lt;button type="submit" class="btn btn-info btn-sm" id="submit"&gt;Enkripsi&lt;/button&gt;
    &lt;/span&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This javascript to send post on php using ajax:</p>
  
  <pre><code>$('#submit').on('click', function(){
    var message = $('#message').val();
  
    var fd = new FormData(this);
    fd.append('file',$('#file')[0].files[0]);
  
    $.ajax({
      method:"POST",
      url:"&lt;?php echo site_url('home/send_chat');?&gt;",    
      data: {fd,message:message},  
      cache: false,
      contentType: false,
      processData: false,   
      success: function(data){                 
        alert(data);
      },
      error: function(xhr, status, error) {
        alert(xhr.responseText);
      }  
    });
  });
  </code></pre>
  
  <p>I'm already try using <code>$_POST['message'];</code> and <code>$this-&gt;input-&gt;post("message");</code> its not work both
  This php to proces code:</p>
  
  <pre><code>&lt;?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  class Home extends CI_Controller {
    public function send_chat()
    {
      $name    = $_FILES['file']['name'];
      $error   = $_FILES['file']['error'];
      $size    = $_FILES['file']['size'];
  
  
      // $message = $_POST['message'];
      $message = $this-&gt;input-&gt;post("message");
  
      $user    = $this-&gt;session-&gt;userdata('username');
      $iduser  = $this-&gt;session-&gt;userdata('userID');
  
  
  
      $insert="insert into chat (user,message,id_user,fileupload) VALUES ('$user','$message','$userid','$name')";
      $this-&gt;db-&gt;query($insert);
    }
  }
  </code></pre>
  
  <p>In database i'm just send name file upload.user, message, and iduser its not send.</p>