title: How to execute a PHP page with HTML in it?
body: <p>I am trying to create a online commenting system using php. This is my php page, with HTML in it. However, it is not executing as expected, with HTML elements being rendered, while php getting returned as garbage during execution. Am I missing something? Do I use .htaccess file to tell the compiler to execute it as purely a php file? </p>
  
  <p><a href="https://s15.postimg.org/r593ht9i3/error.png" rel="nofollow noreferrer">Error image</a></p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;?php
  if (version_compare(phpversion(), "5.3.0", "&gt;=")  == 1)
  error_reporting(E_ALL &amp; ~E_NOTICE &amp; ~E_DEPRECATED);
  else
  error_reporting(E_ALL &amp; ~E_NOTICE); 
  
  require_once('classes/CMySQL.php'); 
  
  $sCode = '';
  $iItemId = (int)$_GET['id'];
  if ($iItemId) { // View item output
  $aItemInfo = $GLOBALS['MySQL']-&gt;getRow("SELECT * FROM `s163_items` WHERE `id` = '{$iItemId}'"); // getting info about item from database
  $sCode .= '&lt;h1&gt;'.$aItemInfo['title'].'&lt;/h1&gt;';
  $sCode .= '&lt;h3&gt;'.date('F j, Y', $aItemInfo['when']).'&lt;/h3&gt;';
  $sCode .= '&lt;h2&gt;Description:&lt;/h2&gt;';
  $sCode .= '&lt;h3&gt;'.$aItemInfo['description'].'&lt;/h3&gt;';
  $sCode .= '&lt;h3&gt;&lt;a href="'.$_SERVER['PHP_SELF'].'"&gt;back&lt;/a&gt;&lt;/h3&gt;';
  
  
  $sComments = '';
  $aComments = $GLOBALS['MySQL']-&gt;getAll("SELECT * FROM `s163_items_cmts`     WHERE `c_item_id` = '{$iItemId}' ORDER BY `c_when` DESC LIMIT 5");
  foreach ($aComments as $i =&gt; $aCmtsInfo) {
      $sWhen = date('F j, Y H:i', $aCmtsInfo['c_when']);
      $sComments .= &lt;&lt;&lt;EOF
  &lt;div class="comment" id="{$aCmtsInfo['c_id']}"&gt;
  &lt;p&gt;Comment from {$aCmtsInfo['c_name']} &lt;span&gt;({$sWhen})&lt;/span&gt;:&lt;/p&gt;
  &lt;p&gt;{$aCmtsInfo['c_text']}&lt;/p&gt;
  &lt;/div&gt;
  EOF;
  }
  
  ob_start();
  ?&gt;
  &lt;div class="container" id="comments"&gt;
      &lt;h2&gt;Comments&lt;/h2&gt;
      &lt;script type="text/javascript"&gt;
      function submitComment(e) {
          var sName = $('#name').val();
          var sText = $('#text').val();
  
          if (sName &amp;&amp; sText) {
              $.post('comment.php', { name: sName, text: sText, id: &lt;?=  $iItemId ?&gt; }, 
                  function(data){ 
                      if (data != '1') {
                        $('#comments_list').fadeOut(1000, function () { 
                          $(this).html(data);
                          $(this).fadeIn(1000); 
                        }); 
                      } else {
                        $('#comments_warning2').fadeIn(1000, function () { 
                          $(this).fadeOut(1000); 
                        }); 
                      }
                  }
              );
          } else {
            $('#comments_warning1').fadeIn(1000, function () { 
              $(this).fadeOut(1000); 
            }); 
          }
      };
      &lt;/script&gt;
  
      &lt;div id="comments_warning1" style="display:none"&gt;Don`t forget to fill both fields (Name and Comment)&lt;/div&gt;
      &lt;div id="comments_warning2" style="display:none"&gt;You can post no more than one comment every 10 minutes (spam protection)&lt;/div&gt;
      &lt;form onsubmit="submitComment(this); return false;"&gt;
          &lt;table&gt;
              &lt;tr&gt;&lt;td class="label"&gt;&lt;label&gt;Your name: &lt;/label&gt;&lt;/td&gt;&lt;td class="field"&gt;&lt;input type="text" value="" title="Please enter your name" id="name" /&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td class="label"&gt;&lt;label&gt;Comment: &lt;/label&gt;&lt;/td&gt;&lt;td class="field"&gt;&lt;textarea name="text" id="text"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
              &lt;tr&gt;&lt;td class="label"&gt;&amp;nbsp;&lt;/td&gt;&lt;td class="field"&gt;&lt;input type="submit" value="Post comment" /&gt;&lt;/td&gt;&lt;/tr&gt;
          &lt;/table&gt;
      &lt;/form&gt;
      &lt;div id="comments_list"&gt;&lt;?= $sComments ?&gt;&lt;/div&gt;
    &lt;/div&gt;
    &lt;?
    $sCommentsBlock = ob_get_clean();
  
    } else {
    $sCode .= '&lt;h1&gt;List of items:&lt;/h1&gt;';
  
   $aItems = $GLOBALS['MySQL']-&gt;getAll("SELECT * FROM `s163_items` ORDER by  `when` ASC"); // taking info about all items from database
      foreach ($aItems as $i =&gt; $aItemInfo) {
      $sCode .= '&lt;h2&gt;&lt;a href="'.$_SERVER['PHP_SELF'].'?  id='.$aItemInfo['id'].'"&gt;'.$aItemInfo['title'].' item&lt;/a&gt;&lt;/h2&gt;';
     }
    }
    ?&gt;
  
  
    &lt;!DOCTYPE html&gt;
    &lt;html lang="en" &gt;
    &lt;head&gt;
      &lt;meta charset="utf-8" /&gt;
      &lt;title&gt;Online commenting system&lt;/title&gt;
      &lt;link href="css/main.css" rel="stylesheet" type="text/css" /&gt;
      &lt;script type="text/javascript" src="js/jquery-1.5.2.min.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;div class="container"&gt;
          &lt;?= $sCode ?&gt;
      &lt;/div&gt;
      &lt;?= $sCommentsBlock ?&gt;
  &lt;/body&gt;
  &lt;/html
  </code></pre>
  
  <p>Please let me know where I am going wrong. Thanks a lot guys!</p>