title: How do I change GET method to POST method using php and ajax
body: <p>I changed the GET methods into POST in php and ajax files but the logical error here is that every time I add a student into the database it doesn't work. I can't really figure out the problem because I'm new to AJAX.</p>
  
  <p>Here's my code:</p>
  
  <p>php file for adding</p>
  
  <pre><code>&lt;?php
  //I changed to POST
  $q1=$_POST["q1"];
  $q2=$_POST["q2"];
  $q3=$_POST["q3"];
  
  $con = mysql_connect('localhost', 'root', '');
  if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
  
  mysql_select_db("stud", $con);
  
  $sql="INSERT INTO stud_info(IDno, LName, FName) VALUES ('$q1', '$q2', '$q3')";
  
  if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
  
  
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>getting the stud id</p>
  
  <pre><code>&lt;?php
  
  $q=$_POST["q"]; //I changed to POST
  
  $con = mysql_connect('localhost', 'root', '');
  if (!$con)
   {
   die('Could not connect: ' . mysql_error());
   }
  
  mysql_select_db("stud", $con);
  
  $sql="SELECT * FROM stud_info WHERE IDno like '".$q."%'";
  
  $result = mysql_query($sql);
  
  echo "&lt;table border='1'&gt;
  &lt;tr&gt;
  &lt;th&gt;IDno&lt;/th&gt;
  &lt;th&gt;LName&lt;/th&gt;
  &lt;th&gt;FName&lt;/th&gt;
  &lt;/tr&gt;";
  
  while($row = mysql_fetch_array($result))
   {
   echo "&lt;tr&gt;";
   echo "&lt;td&gt;" . $row['IDno'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['LName'] . "&lt;/td&gt;";
   echo "&lt;td&gt;" . $row['FName'] . "&lt;/td&gt;"; 
   echo "&lt;/tr&gt;";
   }
  echo "&lt;/table&gt;";
  
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>JavaScript for ajax It doesn't work very well</p>
  
  <pre><code>// JavaScript Document
  var xmlHttp;
  
  function showStud(id)
  { 
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
      var url="getStud.php";
      url=url+"?q="+id;   
      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
  }
  
  function addStud(id, ln, fn)
  { 
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
      var url="addStud.php";
      url=url+"?q1="+id+"&amp;q2="+ln+"&amp;q3="+fn;  
      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
  }
  
  function editStud(id, ln, fn)
  { 
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
      var url="editStud.php";
      url=url+"?q1="+id+"&amp;q2="+ln+"&amp;q3="+fn;
      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
  }
  
  function deleteStud(id)
  { 
      xmlHttp=GetXmlHttpObject();
      if (xmlHttp==null)
      {
          alert ("Browser does not support HTTP Request");
          return;
      }
      var url="deleteStud.php";
      url=url+"?q="+id;   
      xmlHttp.onreadystatechange=stateChanged;
      xmlHttp.open("POST",url,true);
      xmlHttp.send(null);
  }
  
  function stateChanged() 
  { 
      if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
      { 
          document.getElementById("txtHint").innerHTML=xmlHttp.responseText;
      } 
  }
  
  function GetXmlHttpObject()
  {
      var xmlHttp=null;
      try
      {
          // Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
      }
      catch (e)
      {
          //Internet Explorer
          try
          {
              xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
          }
          catch (e)
          {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
      }
      return xmlHttp;
  }
  </code></pre>