title: Javascript : Uncaught SyntaxError: Unexpected token <
body: <p>I have these code, which stores the php variable to a global javascript variable. All the modules are in same file, but still I get an <em>Uncaught SyntaxError: Unexpected token &lt;</em>, at the <strong>rowNum1's</strong> line:-</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
      var glo = 0;
      var rowNum = &lt;?php echo $_GET['SN'];?&gt;;
      var newnames = new Array();
      var rowNum1 = "";
      var tempVal = "";
      var destTextarea = "";
      newnames=&lt;?php echo json_encode($userinfoarr); ?&gt;; //This varaible initialisation works fine
  
  
      function fetchNext(){
              if (glo++ === 0)
              {
                  if(rowNum &lt; newnames.length)
                  {   
                      document.getElementById("Txt0").value = rowNum;
                      document.getElementById("Txt1").value = newnames[rowNum];
                      tempVal = newnames[rowNum];
                  }
                  rowNum++;
              }
              else
              {
                  rowNum1=&lt;?php echo json_encode($sln); ?&gt;; //This one throws an Uncaught Syntax error
                  if(rowNum1 &lt; newnames.length)
                  {   
                      document.getElementById("Txt0").value = rowNum1;
                      document.getElementById("Txt1").value = newnames[rowNum1];
                      tempVal = newnames[rowNum1];
                  }
                  rowNum1++;  
                  console.log("test");
              }
      }
      &lt;/script&gt;
  </code></pre>
  
  <p>This is the php code for <strong>$sln</strong>:</p>
  
  <pre><code>&lt;?php
      if($_SERVER['REQUEST_METHOD'] == 'POST')
      {
          if(isset($_POST['Txt0']))
          {
              $sln = $_POST['Txt0'];
          }
      }
  ?&gt;
  </code></pre>
  
  <p>This is the php code for <strong>$userinfoarr</strong></p>
  
  <pre><code>&lt;?php
      require_once('config.php');
      $result = mysqli_query($conn, "SELECT tweet from tweet");
      $userinfoarr = array();
      while ($row_user = mysqli_fetch_array($result,MYSQLI_ASSOC))
      {
          $userinfo = $row_user["tweet"];
          $push=array_push($userinfoarr, $userinfo);
      }
  ?&gt;
  </code></pre>
  
  <p>COuld anybody help me out with this, as I am unable here to understand the scenario?
  Here is a screenshot of the error inside browser
  <a href="https://i.stack.imgur.com/YvKwO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YvKwO.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/YnVjz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YnVjz.png" alt="enter image description here"></a></p>