Search code examples
phpmysqlquotesmysql-real-escape-string

Mysql or PHP not converting quotes correctly


I have a textarea where users enter some information. Some users enter single and double quotes in their information and what i end up seeing in the page is � and all types of weird characters where single/double quotes are suppose to be. I simply use the function mysqli_real_escape_string() and trim() to store the information and htmleneties() to display them in php.

I my database I already see the � characters so why the single/double quotes are property stored? Thanks!


Solution

  • Inconsistent character sets. Make sure the same character set is used on the database, the database connection, the database table, the table column, the content-type header used when serving the page, and the content-type meta tag of the page. You also want to avoid using PHP string functions on multibyte encodings as they're only safe for iso-8859-1 encoded text. If you plan to accept and display languages other than English you should probably be using UTF-8.