title: Escape Apostrophes in PHP Web Form
body: <p>My PHP form is designed to insert data to a MySQL database. It's working great, except when there is an apostrophe in my input. Then, I get this error: </p>
  
  <p><code>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 'fdfdf','fdfdf')' at line 2</code></p>
  
  <p>This is my first project using PHP. Can someone please provide sample code for how to escape the apostrophe? </p>
  
  <pre><code>&lt;html&gt;
  &lt;body&gt;
  &lt;form action="http://thefaithperspective.com/verses"&gt;
      &lt;input type="submit" value="Add Another" /&gt;
  &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  
  
  &lt;?php
  $servername = "...";
  $username = "...";
  $password = "...";
  $dbname = "...";
  
  $verse= $_POST['verse'];
  $book= $_POST['book'];
  $reference = $_POST['reference'];
  
  
  // Create connection
  $conn = new mysqli($servername, $username, $password, $dbname);
  // Check connection
  if ($conn-&gt;connect_error) {
      die("Connection failed: " . $conn-&gt;connect_error);
  }
  
  $sql = "INSERT INTO myverses (versetext, book, reference)
  VALUES ('$verse','$book','$reference')";
  if ($conn-&gt;query($sql) === TRUE) {
      echo "New record created successfully";
  } else {
      echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
  }
  
  $conn-&gt;close();
  ?&gt;
  </code></pre>