title: How do i include ajax in PHP coding to display data in the same page
body: <p>I want to display data retrieved from the table in the same page. I know if i use ajax, work becomes easier. But how do i do it? I don't know anything about ajax. My current program is combined with html and php. The program is below. All i want is, when i click the button, the requested action and the data must be displayed in the same page. </p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;title&gt;Untitled Document&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;?php
  $dbhost = 'localhost';
  $dbuser = 'root';
  $dbpass = '';
  $dbname = 'DB';
  $conn = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
  if(mysqli_connect_error()) 
  {
  die("couldn't connect" . $conn-&gt;connect_error());
  }
  $id = $_POST['Id'];
  $name = $_POST['Name'];
  $blood = $_POST['BloodGroup'];
  
  if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if(isset($_POST['insert'])){
          $insert = "Insert into ins(Id, name, BloodGroup) values ('$id','$name', '$blood')" ;
          if($conn-&gt;query($insert) === TRUE) {
          echo ("Input data entered successfully");
          } else {
          echo ("Input data failed to be entered" . $conn-&gt;error());
          }
          $conn-&gt;close();
  } elseif(isset($_POST['update'])) {
  
          $update = "update ins set Name='".$name."', BloodGroup='".$blood."' where Id='".$id."'";
          mysql_query($update);
          if($conn-&gt;query($update) === TRUE) {
          echo ("Data updated successfully");
          } else {
          echo ("Data cant be updated" . $conn-&gt;error());
          }
          $conn-&gt;close();
  } elseif(isset($_POST['delete'])) {
          $id = $_POST['Id'];
          $delete = "delete from ins where Id='".$id."'";
          if($conn-&gt;query($delete) === TRUE) {
          echo ("Data deleted successfully");
          } else {
          echo ("Data cant be updated" . $conn-&gt;error());
          }
          $conn-&gt;close();
  }
  else {
  $id = $_POST['Id'];
  $retrieve = "SELECT * FROM ins WHERE Id = ".$id;
  if ($result=mysqli_query($conn,$retrieve))
  {
  while ($row=mysqli_fetch_row($result))
  {
  echo '&lt;table&gt;
  &lt;tr&gt;
  &lt;td&gt;Id&lt;/td&gt;
  &lt;td&gt;Name&lt;/td&gt;
  &lt;td&gt;Blood Group&lt;/td&gt;
  &lt;/tr&gt;
  &lt;tr&gt;
  &lt;td&gt;'.$row[0].'&lt;/td&gt;
  &lt;td&gt;'.$row[1].'&lt;/td&gt;
  &lt;td&gt;'.$row[2].'&lt;/td&gt;
  &lt;/tr&gt;
  &lt;/table&gt;';
  //$row[0],$row[1],$row[2]';
  }
   mysqli_free_result($result);
  }}}
  $conn-&gt;close();
  ?&gt;
  
  &lt;h2&gt;SELECT THE OPERATION YOU WANT TO PERFORM&lt;h2&gt;
  &lt;form method="post" action="&lt;?php echo  htmlspecialchars($_SERVER["PHP_SELF"]);?&gt;"&gt;
  Id: &lt;input type="text" name="Id" /&gt;
  Name: &lt;Input type="text" name="Name" /&gt;
  BloodGroup: &lt;input type="text" name="BloodGroup" /&gt;&lt;br /&gt;&lt;br /&gt;
  &lt;input type="submit" name="insert" value="Insert" /&gt;
  &lt;input type="submit" name="update" value="Update" /&gt;
  &lt;input type="submit" name="delete" value="Delete" /&gt;
  &lt;input type="submit" name="retrieve" value="retrieve" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>