title: PHP variable in bootstrap modal via Ajax
body: <p>I have a php page that lists a bunch of id's from a database. I then have a button next to each id that will open a Twitter Bootstrap modal window in the page and I need to pass the php variable to that model window so that I can do a mysql query in it.</p>
  
  <p>My issue is the model window is just displaying the textbox I setup that should be showing the unique id. However instead it is showing the textbox with just a "null" in it. </p>
  
  <p>My code is below
    The link used to trigger the Modal window. Note I confirmed that the link below does show the value for the php variable.</p>
  
  <pre><code>&lt;a href='#switch_modal' class='btn btn-default btn-small' data-toggle='modal' data-id='$scommentid'&gt;REPLY&lt;/a&gt;
  </code></pre>
  
  <p>Ajax code to get the php variable into the Modal window</p>
  
  <pre><code> &lt;!-- get the unique comment id to use in the modal window --&gt;
    &lt;script&gt;                     
         $(document).ready(function(){
            $('#switch_modal').on('show.bs.modal', function (e) {
                  var rowid = $(e.relatedTarget).data('id');                                                                                                  
                  $.ajax({
                            type : 'post',
                            url : 'fetch_comment_id.php', //Here you will fetch records 
                            data :  'rowid='+ rowid, //Pass $id
                            success : function(data)
                              {
                                   $('.fetched-data').html(data);//Show fetched data from database
                              }
                           });
                       });
                    });
    &lt;/script&gt;
  </code></pre>
  
  <p>This is my modal window code</p>
  
  <pre><code>&lt;div class="modal fade" id="switch_modal" role="dialog"&gt;
    &lt;div class="modal-dialog" role="document"&gt;
        &lt;div class="modal-content"&gt;
          &lt;div class="modal-header"&gt;
              &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
              &lt;h4 class="modal-title"&gt;Edit Data&lt;/h4&gt;
          &lt;/div&gt;
          &lt;div class="modal-body"&gt;
              &lt;div class="fetched-data"&gt;&lt;/div&gt;  
          &lt;/div&gt;
          &lt;div class="modal-footer"&gt;
              &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p></p>
  
  <p>Below is my fetch_comment_id.php file</p>
  
  <pre><code>  &lt;?php
      $id = $_POST['rowid']; //I know I need to clean this variable
      echo "# &lt;input type='text' name='acommentid' value='$id'&gt;";
    ?&gt; 
  </code></pre>