title: Won't Display Updated Database after input (AJAX)
body: <p>I'm sure it has been asked before. But haven't found the answer what I'm looking for. I'm having trouble displaying the <em>UPDATED</em> database once I submit the info. I can only display the outdated database. The database works fine, and I was able to put my entries using AJAX into the database. (I loaded the php files to see if it was updated and it did). But I would like to show it on my initial html page instead. Any help is appreciated. Thanks.</p>
  
  <p>My html file....</p>
  
  <pre><code>&lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
      function getDB(str) 
      {
          if (str == "") {
              document.getElementById("info").innerHTML = "";
              return;
          }
          if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
              xmlhttp = new XMLHttpRequest();
          }
          else {// code for IE6, IE5
              xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
          }
  
          $(function () {
              $("#info").submit(function () {
                  $.ajax({
                      type: "POST",
                      url: "phonebook.php",
                      data: $("#info").serialize(),
                      success: function () {
                          alert("Success!");
                      },
                      error: function () {
                          alert("Error!");
                      }
                  });
                  return false;
              });
          });
  
          xmlhttp.onreadystatechange=function()
          {
           if (xmlhttp.readyState == 4)
           {
               document.getElementById("info").innerHTML = xmlhttp.responseText;
           }
          }
  
         xmlhttp.open("GET","phonebook.php?q="+str,true);
         xmlhttp.send();
  
      }
  &lt;/script&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
  &amp;nbsp;&lt;p&gt;&lt;/p&gt; 
  &lt;form id="info"&gt;
  &lt;table border="0" cellpadding="0" cellspacing="0"&gt;
  &lt;tr&gt;&lt;td&gt;&lt;h3&gt;&lt;/td&gt;&lt;td&gt;Last Name: &lt;input type="text" size="20" id="lastname" name="lastname"&gt;&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;h3&gt;&lt;/td&gt;&lt;td&gt;First Name: &lt;input type="text" size="20" id="firstname" name="firstname"&gt;&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;h3&gt;&lt;/td&gt;&lt;td&gt;Comment: &lt;input type="text" size="20" id="comment" name="comment"&gt;&lt;/h3&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;tr&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;input type="submit" value="Add" border="0" onclick="getDB(this.value)"&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>My PHP file....</p>
  
  <pre><code>&lt;?php
  //$q = intval($_POST['q']);
  if(!($db=new SQLite3('sqlite/phonebook.sqlite3', '0666')))
      {
          echo "&lt;h2&gt;".$TEXT['phonebook-error']."&lt;/h2&gt;";
          die();
      }
  ?&gt;
  
  &lt;?php
  echo "&lt;h3&gt;" .$TEXT['phonebook-head1']. "&lt;/h3&gt;";
  echo "&lt;table border=0 cellpadding=0 cellspacing=0&gt;&lt;tr bgcolor=red&gt;&lt;td&gt;&lt;img src=blank.gif width=10 height=25&gt;&lt;/td&gt;";
  echo "&lt;td class=tabhead&gt;&lt;img src=blank.gif width=150 height=6&gt;&lt;br&gt;&lt;b&gt;" .$TEXT['phonebook-attrib1']. "&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td class=tabhead&gt;&lt;img src=blank.gif width=150 height=6&gt;&lt;br&gt;&lt;b&gt;" .$TEXT['phonebook-attrib2']. "&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td class=tabhead&gt;&lt;img src=blank.gif width=150 height=6&gt;&lt;br&gt;&lt;b&gt;" .$TEXT['phonebook-attrib3']. "&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td class=tabhead&gt;&lt;img src=blank.gif width=75 height=6&gt;&lt;br&gt;&lt;b&gt;" .$TEXT['phonebook-attrib4']. "&lt;/b&gt;&lt;/td&gt;";
  echo "&lt;td&gt;&lt;img src=blank.gif width=10 height=25&gt;&lt;/td&gt;&lt;/tr&gt;";
  ?&gt;
  
  &lt;?php
  $firstname=$db-&gt;escapeString(@$_REQUEST['firstname']);
  $lastname=$db-&gt;escapeString(@$_REQUEST['lastname']);
  $comment=$db-&gt;escapeString(@$_REQUEST['comment']);
  
  if($firstname !="" &amp;&amp; $lastname !="")
  {
      $db-&gt;query("INSERT INTO 'Phone Book' (firstname,lastname,comment) VALUES('$firstname','$lastname','$comment')");
  }
  
  if(@$_REQUEST['action']=="del")
  {
      $db-&gt;query("DELETE FROM 'Phone Book' WHERE id=".round($_REQUEST['id']));
  }
  
  $result=$db-&gt;query("SELECT id,firstname,lastname,comment FROM 'Phone Book' ORDER BY lastname;");
  
  $i=0;
  while( $row=$result-&gt;fetchArray(SQLITE3_ASSOC) )
  {
      if($i&gt;0)
      {
          echo "&lt;tr valign=bottom&gt;";
          echo "&lt;td bgcolor=#ffffff background='border.gif' colspan=6&gt;&lt;img src=blank.gif width=1 height=1&gt;&lt;/td&gt;";
          echo "&lt;/tr&gt;";
      }
      echo "&lt;tr valign=center&gt;";
      echo "&lt;td class=tabval&gt;&lt;img src=blank.gif width=10 height=20&gt;&lt;/td&gt;";
      echo "&lt;td class=tabval&gt;&lt;b&gt;".htmlspecialchars($row['lastname'])."&lt;/b&gt;&lt;/td&gt;";
      echo "&lt;td class=tabval&gt;".htmlspecialchars($row['firstname'])."&amp;nbsp;&lt;/td&gt;";
      echo "&lt;td class=tabval&gt;".htmlspecialchars($row['comment'])."&amp;nbsp;&lt;/td&gt;";
      echo "&lt;td class=tabval&gt;&lt;a onclick=\"return confirm('".$TEXT['phonebook-sure']."');\" href=phonebook.php?action=del&amp;id=".$row['id']."&gt;[".$TEXT['phonebook-button1']."]&lt;/a&gt;&lt;/td&gt;";
      echo "&lt;td class=tabval&gt;&lt;/td&gt;";
      echo "&lt;/tr&gt;";
      $i++;
  
  }
  
  echo "&lt;tr valign=bottom&gt;";
  echo "&lt;td bgcolor=red colspan=6&gt;&lt;img src=blank.gif width=1 height=8&gt;&lt;/td&gt;";
  echo "&lt;/tr&gt;";
  
  $db-&gt;close();
  ?&gt;
  </code></pre>