I have a simple survey page that I was trying to make. Everything worked well except when I used a single quote in my comment on the survey page. When I had a comment with a single quote in it, the DB query wouldn't insert into the DB.
After some Googleing, I assumed I had to escape the string before inserting it into the DB. I used mysqli_real_escape_string to escape the string before INSERTing into the DB, but that doesn't seem to have helped.
Here is my code that inserts the user's comments into the DB ($con not shown for security)
mysqli_real_escape_string($con,$_POST['question_1']);
mysqli_real_escape_string($con,$_POST['question_2']);
mysqli_real_escape_string($con,$_POST['question_3']);
mysqli_real_escape_string($con,$_POST['question_4']);
mysqli_real_escape_string($con,$_POST['question_5']);
mysqli_query($con, "INSERT INTO feedback (question_1, question_2, question_3, question_4, question_5) VALUES ('$_POST[question_1]', '$_POST[question_2]', '$_POST[question_3]', '$_POST[question_4]', '$_POST[question_5]')");
Again, this only happens when the comment contains a single quote. Any suggestions? Did I escape the string incorrectly?