title: Form in Javascript and pass variables to php without refreshing the page
body: <p>I'm new on this form.
  So I'm currently working on a music player website. In this case I want to upload a file in the server. To do this, I want to have a Javascript form and at the click of the button it will execute a function which opens a XMLHttpRequest to another page (upload2.php). In that page I want to "convert" the variables of the form and insert them in my MySQL Database. All without refreshing the page.
  How can I do it?
  I started writing this code (upload and ajax calls functions works correctly, just want to make a javascript form) :</p>
  
  <pre><code>MAIN PAGE:
  
  &lt;html&gt;
  &lt;head&gt;
     &lt;script&gt;
  
      function reqListener () {
          document.getElementById("content1").innerHTML = this.responseText;
      }
  
         function func_upload2() {
         var xmlhttp = new XMLHttpRequest();
         xmlhttp.addEventListener("load", reqListener);
         xmlhttp.open("POST", "upload2.php", true);
         xmlhttp.send();        
     }
  
  
  &lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div id="content1"&gt;
  &lt;h1&gt; UPLOAD &lt;/h1&gt;
  
  &lt;form name="myForm"&gt;&lt;br&gt;
  &lt;input type=file name="pic" accept=".mp3"&gt; &lt;br&gt;
  
  &lt;button type="button" id="upload" name="btn-upload"                                                                                                              
  onclick="func_upload2()"&gt; UPLOAD &lt;/button&gt;&lt;br&gt; 
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  upload2.php:
  
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
          $namefile=$_FILES['pic']['name'];
          $pic = rand(1000,100000) ."-".$_FILES['pic']['name'];
          $pic =$_FILES['pic']['name'];
          $pic_loc = $_FILES['pic']['tmp_name'];
  
          $path="Tracks/".$_SESSION['IdUser'];
          if(!is_dir($path))
             {
                 Mkdir("Tracks/".$_SESSION['IdUser']."/",0777);
             }
          $folder="Tracks/".$_SESSION['IdUser']."/";
          if(move_uploaded_file($pic_loc,$folder.$pic))
          {
              $path1=$folder.$namefile;
              echo $path1;
  
              $insert = $connect-&gt;query("INSERT INTO Tracks (Name,   
              Path, IdUser) VALUES ('".$namefile."', '".$path1."',
              '".$_SESSION['IdUser']."');"); 
              echo "Uploaded!"; 
          }
          else
          {
             echo "Not uploaded";
          }
  ?&gt;
  
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>