title: How to send input file data value using ajax to a php page
body: <p>What I want to do is whenever a user selects a picture and click the button it will move the image to a specific folder and save the link to the database user_image column.</p>
  
  <p>My problem is the actual name of the picture is not save in the database column after i click the submit button. example <code>Oppa/upload/</code> thats the value saved in the database no picture file name.</p>
  
  <p>I think the value of the file didnt receive by photo.php can anyone help me solve it.</p>
  
  <pre><code>&lt;input type='file' id="imageInput" name="imageInput" accept="image/*" /&gt;
  &lt;button  id="changePicture" name="changePicture"&gt;Submit&lt;/button&gt;
  </code></pre>
  
  <p>script:</p>
  
  <pre><code>var data = {};
          data.imageInput = $('#imageInput').val();
          data.email = $('#email').val();
  
          $.ajax({
              type: "POST",
              url: "Oppa/view/photo.php",
              data: data,
              cache: false,
              success: function (response) {
  
              if (Number(response) == 1)
                  {
                     $("#dialog-confirm-changedImage").dialog("open");
                  }
              }
          });
              return false;
  </code></pre>
  
  <p>photo.php</p>
  
  <pre><code>&lt;?php
  include_once('../dbc/database.php');
  
  $db = new Connection();
  $db = $db-&gt;dbConnect();
  $db-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  
  
  $email = isset($_POST['email']) ? $_POST['email'] : "";
  
  $image = addslashes(file_get_contents($_FILES['imageInput']['tmp_name']));
  $image_name = addslashes($_FILES['imageInput']['name']);
  $image_size = getimagesize($_FILES['imageInput']['tmp_name']);
  
  move_uploaded_file($_FILES["imageInput"]["tmp_name"], "Oppa/upload/" . $_FILES["imageInput"]["name"]);
  $location = "Oppa/upload/" . $_FILES["imageInput"]["name"];
  
  
  if(!empty($_POST['email'])) {
  
          $q = "UPDATE tbl_user SET user_image = '$location' WHERE user_email= :email ";
          $query = $db-&gt;prepare($q);
          $query-&gt;bindParam(':email', $email);
          $results = $query-&gt;execute();
          echo "1";
  }
  
  ?&gt;
  </code></pre>