title: Passing MySQL query via Javascript
body: <p>In a Javascript function, I have the following JQuery in which I call a PHP script (i.e. getDBData.php) to get the database data from the query:</p>
  
  <pre><code>$("#dbcontent").load("getDBData.php", {query: "SELECT * FROM `texts` WHERE name='John' LIMIT 10;"});
  </code></pre>
  
  <p>In getDBData, I fetch this query via POST:</p>
  
  <pre><code>$query = $_POST['query'];
  </code></pre>
  
  <p>and give it as input for mysql_query:</p>
  
  <pre><code>$query = mysql_query($query) or die(mysql_error());
  </code></pre>
  
  <p>However, I get the following MySQL error:</p>
  
  <p><em>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'John\' LIMIT 10' at line 1</em></p>
  
  <p>What could be wrong here? I guess it has something to do with character encoding when passing the query, but don't seem to get it right.</p>