Ben
Ben

Reputation: 1233

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!

Upvotes: 0

Views: 966

Answers (2)

genesis
genesis

Reputation: 50976

  • Be sure you have utf8 encoding in DB
  • Be sure you set names

mysql_query("SET NAMES utf8");

  • be sure you set charset in php

header("Content-type: text/html;charset: utf-8");

Upvotes: 0

Dan Grossman
Dan Grossman

Reputation: 52372

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.

Upvotes: 2

Related Questions