title: How to escape quotes when inserting into database with PHP
body: <p>I'm having an error message when inserting content which contains quotes into my db.
  here's what I tried trying to escape the quotes but didn't work:</p>
  <pre><code>$con = mysql_connect(&quot;localhost&quot;,&quot;xxxx&quot;,&quot;xxxxx&quot;);
  if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
  
  mysql_select_db(&quot;test&quot;, $con);
  
  $nowdate = date('d-m-Y')
  
  $title =  sprintf($_POST[title], mysql_real_escape_string($_POST[title]));
  
  $body = sprintf($_POST[body], mysql_real_escape_string($_POST[body]));
  
  $sql=&quot;INSERT INTO articles (title, body, date) VALUES ('$title','$body','$nowdate'),&quot;;
  
  if (!mysql_query($sql,$con))
    {
    
  die('Error: ' . mysql_error());
    
  }
  
  header('Location: index.php');
  </code></pre>