title: JSON Parse Error using Adobe Flex - PHP - SQL
body: <p>I am trying to return results from my SQL database, using PHP to convert it into JSON, which is then read by Flex.</p>
  
  <p>Here is the parse error I receive -</p>
  
  <blockquote>
    <p>JSONParseError: Unexpected &lt; encountered  at
    com.adobe.serialization.json::JSONTokenizer/parseError()[/Users/mesh/src/as3corelib/src/com/adobe/serialization/json/JSONTokenizer.as:579]
      at
    com.adobe.serialization.json::JSONTokenizer/getNextToken()[/Users/mesh/src/as3corelib/src/com/adobe/serialization/json/JSONTokenizer.as:168]
      at
    com.adobe.serialization.json::JSONDecoder/nextToken()[/Users/mesh/src/as3corelib/src/com/adobe/serialization/json/JSONDecoder.as:83]
      at
    com.adobe.serialization.json::JSONDecoder()[/Users/mesh/src/as3corelib/src/com/adobe/serialization/json/JSONDecoder.as:60]
      at
    com.adobe.serialization.json::JSON$/decode()[/Users/mesh/src/as3corelib/src/com/adobe/serialization/json/JSON.as:78]
      at main/getPHPData()[C:\wamp\www\ClassDB\src\main.mxml:25]  at
    main/__getData_result()[C:\wamp\www\ClassDB\src\main.mxml:58]     at
    flash.events::EventDispatcher/dispatchEventFunction()     at
    flash.events::EventDispatcher/dispatchEvent()     at
    mx.rpc.http.mxml::HTTPService/<a href="http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C" rel="nofollow noreferrer">http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[C</a>:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\http\mxml\HTTPService.as:290]  at
    mx.rpc::AbstractInvoker/<a href="http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C" rel="nofollow noreferrer">http://www.adobe.com/2006/flex/mx/internal::resultHandler()[C</a>:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:193]
      at
    mx.rpc::Responder/result()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\Responder.as:43]
      at
    mx.rpc::AsyncRequest/acknowledge()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:74]
      at
    DirectHTTPMessageResponder/completeHandler()[C:\autobuild\3.2.0\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:403]
      at flash.events::EventDispatcher/dispatchEventFunction()    at
    flash.events::EventDispatcher/dispatchEvent()     at
    flash.net::URLLoader/onComplete()</p>
  </blockquote>
  
  <p>And here is the PHP I am using -</p>
  
  <pre><code>&lt;?php
  
  if (isset($_GET['getclassdb']))
      {
      mysql_connect($URL, $USERNAME, $PASSWORD);
      mysql_select_db($DATABASE) or die('Cannot connect to database.');
      $returnArray = array();
      $query = 'SELECT * FROM classdb';
      $result = mysql_query($query);
      while ($row = mysql_fetch_assoc($result))
          {
          array_push($returnArray, $row);
          }
  
      mysql_close();
      echo json_encode($returnArray);
      }
  elseif (isset($_GET['setclassdb']))
      {
      $jsonString = urldecode($_GET['jsonSendData']);
      $jsonString = str_replace("\\", "", $jsonString);
      $data = json_decode($jsonString, true);
      mysql_connect($URL, $USERNAME, $PASSWORD);
      mysql_select_db($DATABASE) or die('Cannot connect to database.');
      foreach($data as $classdbEntry)
          {
          $query = sprintf('UPDATE Tutorials SET rating = "%s" WHERE id = "%s"', mysql_real_escape_string($classdbEntry['rating']) , mysql_real_escape_string($classdbEntry['id']));
          $result = mysql_query($query);
          if (!$result)
              {
              mysql_close();
              echo mysql_error();
              return;
              }
          }
  
      mysql_close();
      echo "database updated";
      }
  
  ?&gt;
  </code></pre>
  
  <p>I am at a complete loss at where to go from here. Any help or hints in the right direction would be greatly appreciated!</p>