0

this is probably an easy question but it is driving me mad. I have a form for users to add comments but if there is a ' symbol in the textarea then it will not upload.

I reckon it might have have something to do with the encoding. I am using phpmyadmin and the encoding for the textarea is utf8_gerenal_ci. But I can manually put this symbol into the database. It is only when it is uploaded through the form which has no character restrictions on the textarea.

There may be more symbols that cannot be uploaded. I don't want to have to stop users from using the ' symbol. Hopefully there is a simple answer even if it does make me look stupid. Thank you for your time.

  • possible duplicate of [how to escape special character in mysql](http://stackoverflow.com/questions/881194/how-to-escape-special-character-in-mysql) – Hanky Panky Sep 23 '14 at 17:55
  • 1
    Don't use old apis for MySQL then. Use prepared statements and those will solve the issue. Just FYI, the issue is escaping the string. All the ' need to be escaped if you are quoting the string vales within ' – Hanky Panky Sep 23 '14 at 17:56

2 Answers2

0

Try using addslashes() before sending form data to database.

eg. $str = $_POST['form_data];

$str = addslashes($str);

This function will escape all such characters which may cause problems while entering in db.

PLease read: http://php.net/manual/en/function.addslashes.php

0

You should do the changes on form part instead of database in this case.

See if this helps you - How to pass apostrophies from text areas to MySQL using PHP

Community
  • 1
  • 1
Domain
  • 11,562
  • 3
  • 23
  • 44