0

I have added mysql_real_escape_string() with a query for text inputs. When a user writes text with symbols it passes through mysql_real_escape_string() and works fine, but when the user pastes text copied from other websites it won't pass through mysql_real_escape_string(). The text after the apostrophe is cut off.

How can I fix this?

I believe when user pastes text in input field it's not in UTF-8 encoding. Is there any way to process it without errors in core PHP? Also please tell me if you have solutions in Pear DB.

Sebastian Zartner
  • 18,808
  • 10
  • 90
  • 132
Hemant
  • 1
  • 2
  • Is the text getting cut off or are there errors? If there are errors, what are they? – Quentin Mar 04 '14 at 09:31
  • You really should show more code. `mysql_real_escape_string` should handle any escaping needed. – Quentin Mar 04 '14 at 09:46
  • You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Mar 04 '14 at 09:46

1 Answers1

0

I am assuming users may also paste URL encoded text, so use urldecode function in PHP. That could be one of the possible cases. Another one is as you said UTF-8, in that case use MySQL's CONVERT function. I hope this helps. If possible please provide more details like for what texts you are getting this problem.

Varun Kakumani
  • 117
  • 1
  • 18