title: Jquery/AJAX populated HTML form when dropdown selected
body: <p>I am trying to populate a form on my  page.  The information required to populate the form is pulled from a MySQL database using the ID of the drop down option as the ID in the SQL statement.  I was thinking that I can store the information in $_SESSION['formBookings'] and on a refresh this will populate the form (this is already happening as I am using the session variable to populate the form after a submit.</p>
  
  <p>I can not have a submit button attached to the form as I already have one and the boss doesn't want another.  I would like the form to eventually automatically refresh the page on the selection of an option.  If the data from the SQL statement has been stored in the session array then the form will be populated.</p>
  
  <p>Here is what I have so far:</p>
  
  <p>The JQuery:</p>
  
  <pre><code>&lt;script&gt;
  $(document).ready(function(){
      $('select[name=recall]').on('change', function() {var recall = $(this).val() 
      //$(function () 
        //{
          //-----------------------------------------------------------------------
          // 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
          //-----------------------------------------------------------------------
          $.ajax({                                      
            url: 'recall.php',                  //the script to call to get data          
            data: "recall: recall",             //you can insert url argumnets here to pass to api.php
                                             //for example "id=5&amp;parent=6"
            dataType: 'json',                //data format      
            success: function(data)          //on recieve of reply
            {
              var id = data[0];              //get id
              var vname = data[1];           //get name
              //--------------------------------------------------------------------
              // 3) Update html content
              //--------------------------------------------------------------------
              $('div#box1').load('DFBristol.html');//html("&lt;b&gt;id: &lt;/b&gt;"+id+"&lt;b&gt; name: &lt;/b&gt;"+vname); //Set output element html
              //recommend reading up on jquery selectors they are awesome 
              // http://api.jquery.com/category/selectors/
            //} 
            });
          });
        });
      });
  &lt;/script&gt;
  </code></pre>
  
  <p>The HTML:</p>
  
  <pre><code>&lt;select name='recall' id='recall'&gt;
                      &lt;option selected&gt;&lt;/option&gt;
                          &lt;?php
                              session_start();
                              $user = 'root';
                              $pass = '';
  
                              $DBH = new PDO('mysql:host=localhost;dbname=nightlineDB;', $user, $pass);
                              $DBH-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                              $DBH-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  
                              $recall = $DBH-&gt;prepare('SELECT * FROM bookings WHERE dateInputted &gt;= now() - INTERVAL 2 DAY');
                              $recall-&gt;execute();
                              $recallResult = $recall-&gt;fetchALL(PDO::FETCH_ASSOC);
  
                              foreach ($recallResult as $key) {
                                  echo '&lt;option id='.$key["ID"].'&gt;'.$key['ID'].' - '.$key['branch'].' - '.$key['title'].' '.$key['firstName'].' '.$key['lastName'].'&lt;/option&gt;';
                              }
                          ?&gt;
                      &lt;/select&gt;&lt;br /&gt;
  </code></pre>
  
  <p>The SQL file (recall.php):</p>
  
  <pre><code>&lt;?php
  $user = 'root';
  $pass = '';
  
  $DBH = new PDO('mysql:host=localhost;dbname=nightlineDB;', $user, $pass);
  $DBH-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  $DBH-&gt;setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
  
  $recall = $DBH-&gt;prepare("SELECT * FROM bookings WHERE ID = '%$recall%'");
  $recall-&gt;execute();
  $recallFormResult = $recall-&gt;fetchALL(PDO::FETCH_ASSOC);
  
  echo json_encode($recallFormResult);
  </code></pre>
  
  <p>?></p>
  
  <p>I have tried to pass the variable 'recall' from the jquery into the SQL statement using the data argument but nothing happens.</p>
  
  <p>Could someone please help me understand what I am doing wrong and how I can resolve it.</p>