title: Insert into mysql with php - data has backticks in it
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/7673009/mysql-single-quote-insertion-error">MySQL single quote insertion error</a>  </p>
  </blockquote>
  
  
  
  <p>I've got a query that duplicates rows.  The problem is some of the data has back ticks in it so the query does not execute correctly. </p>
  
  <p>For example the field question has the following statement:  <strong><em>The horse’s hoof ......</em></strong></p>
  
  <p>How do I go about this?</p>
  
  <pre><code>$tid_dup1 = 11;
  $newtestid= 21;
  
  $sql3="SELECT * FROM ex_q WHERE test_name = '$tid_dup1'";
  $res3=mysql_query($sql3);
  while($row3 = mysql_fetch_assoc($res3)) {
  $id=$row3['id'];
  $q_nr=$row3['q_nr'];
  $q_type=$row3['q_type'];
  $pic=$row3['pic'];
  $question=$row3['question'];
  mysql_query("INSERT INTO ex_question (id,test_name,q_nr,q_type,pic,question) VALUES ('0','$newtestid','$q_nr','$q_type','$pic','$question')");
  if (mysql_affected_rows() == 1) {
  echo "inserted $q_nr duplicated row $id";
  }
  }
  </code></pre>