title: Escaping sigle quotes in a mysql query through php
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/2284099/mysql-real-escape-string-php-function-adding-to-my-field-entry">Mysql Real Escape String PHP Function Adding &ldquo;\&rdquo; to My Field Entry</a>  </p>
  </blockquote>
  
  
  
  <p>So here's the deal. I have a local server and a remote server and they both run the same php file which connects to 2 identical mysql databases. On the local server, the command</p>
  
  <pre><code>mysql_query("INSERT INTO eventtypes (name) VALUES ('".addslashes($_GET['name'])."')")
  </code></pre>
  
  <p>works like a charm, and does not insert the slashes into the field, only the raw value of the $_GET['name']. On the remote server however, the slashes are being inserted too. I have tried these:</p>
  
  <pre><code>mysql_query("INSERT INTO eventtypes (name) VALUES ('".str_replace("'","''",$_GET['name'])."')
  </code></pre>
  
  <p>This one returns false, although when I run the exact returned string on the command line of the corresponding database, it properly inserts the right amount of single quotes, which is super-weird.</p>
  
  <pre><code>mysql_query("INSERT INTO eventtypes (name) VALUES ('".mysql_real_escape_string($_GET['name'])."')")
  </code></pre>
  
  <p>mysql_real_escape_string() only added slashes to the single quotes, which were also inserted like with addslashes().</p>