title: Can I insert php & html inside a multi line php variable?
body: <p>So I'm a total beginner and I'm working on a project to create dynamic dropdown forms. I have written some code and am wondering now if I can insert php &amp; html inside a multi line php variable. This code below is what I just tried[javascript not included here] but php shows error. Is this not possible at all or is it some error on my part? Thanks in advance.</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
  &lt;head&gt;
      &lt;title&gt;php &amp; html inside a multi line php variable&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;?php 
      $chooseroom=&lt;&lt;&lt;HERE
      &lt;div class="select-boxes"&gt;
          &lt;?php
          //Include database configuration file
          include('dbConfig.php');
  
          //Get all occupation data
          $query = $db-&gt;query("SELECT * FROM occupations WHERE status = 1 ORDER BY occupation_name ASC");
  
          //Count total number of rows
          $rowCount = $query-&gt;num_rows;
          ?&gt;
          &lt;select name="occupation" id="occupation"&gt;
              &lt;option value=""&gt;Select occupation&lt;/option&gt;
              &lt;?php
              if($rowCount &gt; 0){
                  while($row = $query-&gt;fetch_assoc()){ 
                      echo '&lt;option value="'.$row['occupation_id'].'"&gt;'.$row['occupation_name'].'&lt;/option&gt;';
                  }
              }else{
                      echo '&lt;option value=""&gt;occupation not available&lt;/option&gt;';
                  }
              ?&gt;
          &lt;/select&gt;
  
          &lt;select name="specification" id="specification"&gt;
              &lt;option value=""&gt;Select occupation first&lt;/option&gt;
          &lt;/select&gt;
  
          &lt;select name="expertise" id="expertise"&gt;
              &lt;option value=""&gt;Select specification first&lt;/option&gt;
          &lt;/select&gt;
      &lt;/div&gt;
      HERE;
      echo $chooseroom;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>OK AS REQUESTED BY SOME OF YOU HERE IS MY JAVASCRIPT:</p>
  
  <pre><code>&lt;script src="jquery.min.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript"&gt;
  $(document).ready(function(){
  $('#occupation').on('change',function(){
      var occupationID = $(this).val();
      if(occupationID){
          $.ajax({
              type:'POST',
              url:'ajaxData.php',
              data:'occupation_id='+occupationID,
              success:function(html){
                  $('#specification').html(html);
                  $('#expertise').html('&lt;option value=""&gt;Select specification first&lt;/option&gt;'); 
              }
          }); 
      }else{
          $('#specification').html('&lt;option value=""&gt;Select occupation first&lt;/option&gt;');
          $('#expertise').html('&lt;option value=""&gt;Select specification first&lt;/option&gt;'); 
      }
  });
  
  $('#specification').on('change',function(){
      var specificationID = $(this).val();
      if(specificationID){
          $.ajax({
              type:'POST',
              url:'ajaxData.php',
              data:'specification_id='+specificationID,
              success:function(html){
                  $('#expertise').html(html);
              }
          }); 
      }else{
          $('#expertise').html('&lt;option value=""&gt;Select specification first&lt;/option&gt;'); 
      }
  });
  });
  &lt;/script&gt;
  </code></pre>