title: Simplest jQuery, PHP, AJAX, and sqlite example?
body: <p>I'm having a really difficult time understanding how this all works together. I've fiddled for a few days with this and have been unable to come up with any results. I'm trying to fill in a text field in a form, and when the form is submitted, I want to add the text to my sqlite db using ajax. </p>
  
  <p>I understand that you need a $.get call in jquery which is triggered on the form's submit. That seems to work fine as I can trigger js alert boxes from there. However, when I pass the address of the php script which has lines to add to the sqlite db using PDO, nothing is added to the db. However, when I run this php script from using php cli, something will get added to the db.</p>
  
  <p>I seem to be missing an essential step here. I would really appreciate it if someone could bridge this gap for me!</p>
  
  <p>Edit:
  As requested by Martin here's some code:</p>
  
  <p>My php generates some list like this with a form in the middle:</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;hello&lt;/li&gt;
      &lt;li id="formItem"&gt;
          &lt;form action="" method="post"&gt;
              &lt;input type=text name="content"/&gt;
          &lt;/form&gt;
      &lt;/li&gt;
      &lt;li&gt;world&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>Then my jquery code looks to add whatever is in the textbox right above it on the list does an ajax call. This is inside a $(document).ready(function(){.</p>
  
  <pre><code> $("form").submit(function() {
      var inputText = $("input").val();
      $.ajax({
          type: "POST",
          url: "add.php",
          data: inputText,
          success: function() {
              $('#formItem').prev().after(
                  "&lt;li&gt;" + inputText + "&lt;/li&gt;"
              )}
      });
  });
  </code></pre>
  
  <p>My add.php file looks like this and it will insert something into my db if I execute the php script on the cli:</p>
  
  <pre><code>&lt;?php 
  $base = new PDO('sqlite:todo.db');
  $sql = $base-&gt;prepare("INSERT INTO ThisTable (content, priority) VALUES ('lolololol', 1);");
  $sql-&gt;execute();
  $base = null; 
  ?&gt;
  </code></pre>