title: How to write php code in script tag?
body: <p>I am trying to write php code in script tag but something seems to be going wrong.
  Here is the complete code:</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;?php
  if(isset($_GET['column-count']))
  $var = $_GET['column-count']; 
  ?&gt;
  
  &lt;html&gt;
      &lt;head&gt;
          &lt;title&gt;Index&lt;/title&gt;
          &lt;script&gt;
  
              function send_column_count(){
              var col_count = document.getElementById('num-cols').value;
              alert(col_count);
              document.getElementById('column-count-id').value =   col_count ;
              var temp = document.getElementById('column-count- id').value;
              alert(temp);
  
              &lt;?php
                  for($i = 0;$i &lt; $var ;$i = $i+1){
                  $temp = "col".$i;
              echo " &lt;input type='text' placeholder='column- name' id='" . $temp . "' /&gt;";
                  }
              ?&gt;
              alert('Reached here');
  
              return true;
          }
  
  &lt;/script&gt;
  
      &lt;/head&gt;
      &lt;body&gt;
          &lt;form align="center" method="GET" action="" &gt;
              &lt;h1&gt;Snippt&lt;/h1&gt;
              &lt;select id="num-cols" onchange="send_column_count()"&gt;
                  &lt;option&gt;1&lt;/option&gt;
                  &lt;option&gt;2&lt;/option&gt;
                  &lt;option&gt;3&lt;/option&gt;
                  &lt;option&gt;4&lt;/option&gt;
                  &lt;option&gt;5&lt;/option&gt;
              &lt;/select&gt;
  
              &lt;input type="hidden" name="column-count" id="column-count-id" value="7" /&gt;
              &lt;input type="submit" name="Submit" value="Create Table" /&gt;
  
          &lt;/form&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Now the console shows the error message : Unexpected token &lt;
  I am not able to understand what's going wrong!</p>