I am trying to insert a ♥ into a MySQL table with PHP. It comes from an input field.
The table's charset is utf8_general_ci, and in PHP I use mysql_query("SET NAMES 'utf8'");
right after connection is made.
But the ♥ just becomes a '?' when inserted.
I have also tried inserting ♥ into the table from phpMyAdmin, but it returns this error:
Warning: #1366 Incorrect string value: '\xE2\x99\xA5' for column 'subject' at row 1
The result is also '?' instead of ♥.
Any ideas on what causes this?
This is because of incompatible character set and collation defined on table's column.
Try changing character set of your table or column to UTF8
.
ALTER TABLE table_name CONVERT TO CHARACTER SET utf8;
or
ALTER TABLE table_name MODIFY col VARCHAR(255) CHARACTER SET utf8;
try this:
ini_set('default_charset', 'utf-8');
in your php file and set the :
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
and chek in you data base for collation to utf8_general_ci
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.