title: Why does not insert these values in database using Ajax
body: <p>I used tutorialspoint to guide me to insert the values from input text into the db, but unfortunately, it will not insert to the database. Is this correct implementation for AJAX? </p>
  
  <h2>Here's my index.php</h2>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  
  &lt;script language="javascript" type="text/javascript"&gt;
  &lt;!-- 
  //Browser Support Code
  function ajaxFunction(){
     var ajaxRequest;  // The variable that makes Ajax possible!
     try{
  
        // Opera 8.0+, Firefox, Safari
        ajaxRequest = new XMLHttpRequest();
     }catch (e){
  
        // Internet Explorer Browsers
        try{
           ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
        }catch (e) {
  
           try{
              ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
           }catch (e){
  
              // Something went wrong
              alert("Your browser broke!");
              return false;
           }
        }
     }
  
     // Create a function that will receive data
     // sent from the server and will update
     // div section in the same page.
     ajaxRequest.onreadystatechange = function(){
  
        if(ajaxRequest.readyState == 4){
           var ajaxDisplay = document.getElementById('ajaxDiv');
           ajaxDisplay.innerHTML = ajaxRequest.responseText;
        }
     }
  
  
     // Now get the value from user and pass it to
     // server script.
     var fname = document.getElementById('fname').value;
     var lname = document.getElementById('lname').value;
     var gen = document.getElementById('gen').value;
    // var queryString = "?age=" + age ;
  
      queryString +=  "&amp;fname=" + fname + "&amp;lname=" + lname+ "&amp;gen=" + gen;
     ajaxRequest.open("GET", "ajax.php" + queryString, true);
     ajaxRequest.send(null); 
  }
  //--&gt;
  &lt;/script&gt;
  
  &lt;form name='myForm'&gt;
  
     First Name: &lt;input type='text' id='fname' /&gt; &lt;br /&gt;
     Last Name: &lt;input type='text' id='lname' /&gt; &lt;br /&gt;
     Sex: 
     &lt;select id='gen'&gt;
        &lt;option value="m"&gt;m&lt;/option&gt;
        &lt;option value="f"&gt;f&lt;/option&gt;
     &lt;/select&gt;
     &lt;input type='button' onclick='ajaxFunction()' value='Query MySQL'/&gt;
  
  &lt;/form&gt;
  &lt;div id='ajaxDiv'&gt;Your result will display here&lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <h2>ajax.php</h2>
  
  <pre><code>&lt;?php
  $dbhost = "localhost";
  $dbuser = "root";
  $dbpass = "";
  $dbname = "my_db";
  
  
  $con =  new mysqli($dbhost, $dbuser, $dbpass,$dbname);
  
  
  $query="INSERT INTO table1 (fname, lname, gender)
  VALUES
  ('$_GET[fname]','$_GET[lname]','$_GET[gen]')";
  
  $qry_result = $con-&gt;query($query);
  
  
  ?&gt;
  </code></pre>