This question already has an answer here:
Closed 11 years ago.
Possible Duplicate:
Insert into database problem… (Bad character coding) PHP/MYSQL
I have a form which is submitted into a mysql database. The database is set to UTF-8_GENERAL and the rows are using the same character coding as well.
But when I submit the form with a "ő" or "ű" in the text, it does not submit anything after these characters. (Example: "This is a nice ű day." It just inserts this into the db: "This is a nice")
The form validation page has the mysql_real_escape_string(); strip_tags(); before submitting to the db.
I echo out the result after every string function (mentioned above). It all works fine, but when it gets inserted, it doesn't display anything after those characters.
[MySql version: 5.0.51a-24+lenny5-log | Using phpMyAdmin version: 2.11.8.1deb5+lenny7]
How could I solve this? Any help appreciated...
encode the characters:
$string = mb_convert_encoding($variable, 'HTML-ENTITIES', 'UTF-8');
Related
This question already has answers here:
How to make MySQL handle UTF-8 properly
(15 answers)
UTF-8 all the way through
(13 answers)
Closed 5 years ago.
I'm new to php, i made a php user interface with input fields that formulates, prints and execute a query showing the database reply or error.
It usually works fine but when i make a query with accented fields like in
"INSERT INTO `Nave` (`Targa`, `Nazionalità`, `Nome`) VALUES('0', 'italia', 'nave0');"
php successfully creates the query, prints and executes it without any further modifications but it fails saying "Unknown column 'Nazionalità' in 'field list'"
but if i copy/paste the same exact query printed by php into phpmyadmin it works (so obiouvsly the column 'Nazionalità' does exist) what is happening?
Notice that if the php generated query has no fields with accent it works even in php.
Notice also that individually neither my php nor mysql have any issues dealing with accent. so it's NOT a duplicate of How to make MySQL handle UTF-8 properly because that's a mysql individual issues, my database works fine.
EDIT: All the answers so far explained how to fix the database, but the database does works fine!
I do not know how to make it understand that, read more about the question guys...
But the second duplicate suggestion was quite right and there i found my solution which I copy here for convenience of those who will visit this page having the same problem: "$mysqli->set_charset('put here the same charset used in your db');" OR "mysqli_set_charset($link, 'charset');"
Thank for your help.
change your character set of database to UTF-8 by following MySQL query
ALTER TABLE Nave CONVERT TO CHARACTER SET utf8;
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 6 years ago.
I'm creating a messaging system with PHP and MySQL but am having problems when certain characters are entered. Particularly the Pound sign (£).
The form where users write their message is POSTed to a PHP script with the following functions:
$message = htmlspecialchars($message, ENT_QUOTES);
$message = utf8_encode($message);
Then $message is INSERTed into a Database where it is stored in a Text Column.
However, when inputing a Pound sign no data appears in the database at all on my live server, but on my localhost (using MAMP) £ appears in the database.
Anybody know whats going on? And is there a way to encode £ as £, I feel like that might solve my issue.
If your database encoding is not UTF-8, or if the application does not retrieve data from the database as UTF-8, data stored in the database will not render correctly.Check your db encoding please and if this is not the problem put this to your php page
header('Content-Type: text/html; charset=utf-8');
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I displayed some Russian words on HTML and it showed like following.
Полный кадр
The result is:
Полный кадр
I tried to convert the original string to UTF8 and displayed in HTML. I showed like above.
Some information:
store field collation: latin1_swedish_ci
The sql result is :
ÐолнÑй кадÑ
I queried the database and get the value. And then convert to utf8:
mb_convert_encoding($value, 'utf-8', 'windows-1251');
Could you please take a look at this link. Someone fixed it:
http://stackoverflow.com/questions/13765242/need-help-determining-encoding-of-the-text
The problem is I'm rebuilding a website. Some data is from old website. And I cannot input it manually because It's a lot. So I wrote a php script to get data from the old website and inserted to my new website. The old website display russian in HTML perfectly. But I didn't code it, and I cannot see his code.
I already check the data between old table and new table. It's the same.
You should change collation for your table to e.g. utf8_unicode_ci, or koir... for Russian, so you can get the right result. latin_swedish does not support Cyrillic characters.
This question already has answers here:
UTF-8 all the way through
(13 answers)
Closed 8 years ago.
I'm building a php search page for a photo gallery to pull data with Chinese characters from MySQL.
I've done the following:
1. setting webpage to utf-8 encoding meta http-equiv="content-type" content="text/html";charset="utf-8"
2. ensure that the collation for mysql db and data itself is utf8_general_ci
3. set chrome encoding to utf-8.
But when I put in a positive search string to pull data with Chinese characters, they always come up as ???
I've checked my php array raw output and it is also ??? which leads me to believe there is something wrong at my database end. But I need to add is my gallery page (where the search box is embedded) displays the Chinese characters correctly from the same database.
Have you also set $mysqli->set_charset('utf8'); ?
This question already has answers here:
UTF-8 all the way through
(13 answers)
Insert into a table which has a dash in the name
(4 answers)
Closed 8 years ago.
While inserting data "Jack - Jill" in mysql db, it saving as "Jack †Jill“, my problem is when i tried to display the string in page its showing like "Jack �€� Jill", i am just botherd to display the string properly like "Jack - Jill", i tried have proper charactersets but not much of luck.
make sure you specify the charset used by your page to the database (and all its tables), and the other way around. i.e.:
Give your page a metatag and the script witing to the database a line that either validates that the charset is UTF-8 (example charset), or that it converts the chaarset to UTF-8
and give your database the same property, that it saves and reads data as UTF-8 (i use PHPMyAdmin, if you use such GUI tools too, its just a checkbox away).
hope i pointed you into the right direction