title: Unexpected < token in JSON at position 0
body: <p>I keep receiving this JSON error,i think it has something to do with html tags or any other tags that conflicts with it. </p>
  
  <p>Here is my PHP Code:</p>
  
  <pre><code> &lt;?php
      require_once("connection.php");
  
      class AddAdminUPController extends Connection{
  
          public function addAdminUP(){
              include "function.php";
              $username = cleanData($_POST['username']);
              $password = cleanData($_POST['password']);
              if (!empty($username)){
                  if(!empty($password)){
                      if(strlen($password) &gt; 8){
                          $select_query = "select * from sample_user where user_name = ?";
                          $stmt = $this-&gt;db-&gt;prepare($select_query);
                          $stmt-&gt;bindParam(1,$username);
                          if($stmt-&gt;execute()){
                              if($stmt-&gt;rowCount() &lt;= 0){
                                  $password = password_hash($password,PASSWORD_BCRYPT,array('cost' =&gt; 12));
                                  $create_query = "insert into sample_user(user_name,password)values(?,?)";
                                  $stmt = $this-&gt;db-&gt;prepare($create_query);
                                  $stmt-&gt;bindParam(1,$username);
                                  $stmt-&gt;bindParam(2,$password);
                                  if($stmt-&gt;execute()){
                                      echo "&lt;script&gt;".
                                           "Materialize.toast('Created SuccessFully!', 5000, 'green')"
                                          ."&lt;/script&gt;";
                                      echo "&lt;script&gt;".
                                           "$('#add_admin_up_form').hide();".
                                           "$('#add_admin_up').hide();";
                                      ?&gt;
  
                                      $(".enrollment_title").html("&lt;i class='material-icons'&gt;fingerprint&lt;/i&gt; Enroll Fingerprint");
  
                                      &lt;?php
                                      echo "&lt;/script&gt;";
  
                                      include 'flexcode_sdk/include/global.php';
                                      include 'flexcode_sdk/include/function.php';
                                      if(isset($_GET['action']) &amp;&amp; $_GET['action'] == 'add'){
                                          $lastID = $this-&gt;db-&gt;lastInsertId();
                                      ?&gt;
  
                                      &lt;script type="text/javascript"&gt;
  
                                          $('title').html('User');
                                          function user_register(user_id, user_name) {
  
                                              $('body').ajaxMask();
  
                                              regStats = 0;
                                              regCt = -1;
                                              try
                                              {
                                                  timer_register.stop();
                                              }
                                              catch(err)
                                              {
                                                  console.log('Registration timer has been init');
                                              }
  
                                              var limit = 4;
                                              var ct = 1;
                                              var timeout = 5000;
  
                                              timer_register = $.timer(timeout, function() {
                                                  console.log("'"+user_name+"' registration checking...");
                                                  user_checkregister(user_id,$("#user_finger_"+user_id).html());
                                                  if (ct&gt;=limit || regStats==1)
                                                  {
                                                      timer_register.stop();
                                                      console.log("'"+user_name+"' registration checking end");
                                                      if (ct&gt;=limit &amp;&amp; regStats==0)
                                                      {
                                                          alert("'"+user_name+"' registration fail!");
                                                          $('body').ajaxMask({ stop: true });
                                                      }
                                                      if (regStats==1)
                                                      {
                                                          $("#user_finger_"+user_id).html(regCt);
                                                          alert("'"+user_name+"' registration success!");
                                                          $('body').ajaxMask({ stop: true });
                                                          load('view_admin.php?action=add');
                                                      }
                                                  }
                                                  ct++;
                                              });
                                          }
  
                                          function user_checkregister(user_id, current) {
                                              $.ajax({
                                                  url         :   "view_admin.php?action=checkreg&amp;user_id="+user_id+"&amp;current="+current,
                                                  type        :   "GET",
                                                  success     :   function(data)
                                                                  {
                                                                      try
                                                                      {
                                                                          var res = jQuery.parseJSON(data);
                                                                          if (res.result)
                                                                          {
                                                                              regStats = 1;
                                                                              $.each(res, function(key, value){
                                                                                  if (key=='current')
                                                                                  {
                                                                                      regCt = value;
                                                                                  }
                                                                              });
                                                                          }
                                                                      }
                                                                      catch(err)
                                                                      {
                                                                          alert(err.message);
                                                                      }
                                                                  }
                                              });
                                          }
  
                                      &lt;/script&gt;
  
                                      &lt;?php
  
                                          $last_id_query = "select * from sample_user where user_id = ?";
                                          $stmt = $this-&gt;db-&gt;prepare($last_id_query);
                                          $stmt-&gt;bindParam(1,$lastID);
                                          if ($stmt-&gt;execute()){
                                              while($row = $stmt-&gt;fetch(PDO::FETCH_OBJ)){
  
                                                  $url_register =
                                                  base64_encode($base_path."register.php?user_id=".$row-&gt;user_id);
                                                  echo "&lt;br&gt;&lt;a href='finspot:FingerspotReg;$url_register' onclick=\"user_register('".$row-&gt;user_id."','".$row-&gt;user_name."')\" class='fw_button general_button btn waves-effect waves-light'&gt;Register Fingerprint&lt;/a&gt;";
                                              }
                                          }
                                      }
                                      elseif (isset ($_GET['action']) &amp;&amp; $_GET['action'] == 'checkreg') {
  
                                              $sql1       = "SELECT count(finger_id) as ct FROM sample_finger WHERE user_id=".$_GET['user_id'];
                                              $result1    = mysql_query($sql1);
                                              $data1      = mysql_fetch_array($result1);
                                              if (intval($data1['ct']) &gt; intval($_GET['current'])) {
                                                  $res['result'] = true;
                                                  $res['current'] = intval($data1['ct']);
                                              }
                                              else
                                              {
                                                  $res['result'] = false;
                                              }
                                              echo json_encode($res);
                                      }
                                      else { echo "Parameter invalid..";}
                                  }
                                  else{
                                      echo "&lt;script&gt;".
                                           "Materialize.toast('Query Failed!', 5000, 'red')"
                                          ."&lt;/script&gt;";
                                  }
                              }
                              else{
                                  echo "&lt;script&gt;".
                                       "Materialize.toast('Username already exists!', 5000, 'red')"
                                      ."&lt;/script&gt;";
                              }
                          }
                          else{
                              echo "&lt;script&gt;".
                                   "Materialize.toast('Query Failed!', 5000, 'red')"
                                  ."&lt;/script&gt;";
                          }
                      }
                      else{
                          echo "&lt;script&gt;".
                               "Materialize.toast('Password is too short!', 5000, 'red')"
                              ."&lt;/script&gt;";
                      }
                  }
                  else{
                      echo "&lt;script&gt;".
                           "Materialize.toast('Password is empty!', 5000, 'red')"
                          ."&lt;/script&gt;";
                  }
              }
              else{
                  echo "&lt;script&gt;".
                       "Materialize.toast('Username is empty!', 5000, 'red')"
                      ."&lt;/script&gt;";
              }
  
          }
      }
  $add_admin_up_controller = new AddAdminUPController;
  echo $add_admin_up_controller-&gt;addAdminUP();
  
  ?&gt;
  </code></pre>
  
  <p>I need help in fixing this kind of error. It keeps displaying:</p>
  
  <blockquote>
    <p>SyntaxError: Unexpected token &lt; in JSON at position 0 at JSON.parse () at Function.jQuery.parseJSON (jquery.js:8520) at Object.success (eval at  (jquery.js:339), :55:90) at fire (jquery.js:3148) at Object.fireWith [as resolveWith] (jquery.js:3260) at done (jquery.js:9314) at XMLHttpRequest.callback (jquery.js:9718) </p>
  </blockquote>