Page 1 of 1

Mysql problem with ñ and Ñ - SOLVED

Posted: Fri Sep 12, 2008 1:27 am
by deeessay
Hi!

When I entered strings with ñ and Ñ, they will be saved in the database as is with no problem.

However, when retrieved from the database, ñ becomes ñ and Ñ becomes Ñ

Is there any way that when I fetched the results from the database, the special characters will remain intact?

Re: Mysql problem with ñ and Ñ

Posted: Fri Sep 12, 2008 8:28 am
by BETA
I had this same problem i solved it when saving things to db using htmlentities...
Example:

Code: Select all

 
$ctitle = htmlentities($title);
$msg = htmlentities($message);
$query = "INSERT INTO news_posts (title, author, post, DATE) VALUES ('$ctitle', '$nam', '$msg', NOW())";
hope this helps!

Re: Mysql problem with ñ and Ñ

Posted: Fri Sep 12, 2008 9:32 am
by Jenk
It's not an issue with MySQL, it's an issue with your pages encoding. Remember to set it with the relevant HTTP header or meta content-type.

This is also not the correct forum to ask coding or database questions. There are two forums for both.

Re: Mysql problem with ñ and Ñ

Posted: Fri Sep 12, 2008 11:15 pm
by deeessay
Thank you all for replying!

I used

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");

and the ñ and Ñ are now saved in the database as is. My problem now is when fetched from the database, the characters are different. I tried using

htmlentities
htmlspecialchars
htmlspecialchars_decode
and
html_entity_decode

but to no avail...

Mysql problem with ñ and Ñ -- SOLVED

Posted: Sat Sep 13, 2008 2:44 am
by deeessay
Hi again, I finally got it working. Thanks to Jenk and BETA for helping. For the benefit of those who will encounter the same problem in the future, here's what I did:


query these first before inserting or updating the database:

mysql_query("SET NAMES 'utf8'");
mysql_query("SET CHARACTER SET 'utf8'");



then, on the page that will display the special characters, add this in between the <head></head> tags:

<meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />

Re: Mysql problem with ñ and Ñ - SOLVED

Posted: Sat Sep 13, 2008 2:52 am
by BETA
Np!
Well ur solution doesn't work for me cause i can't print characters like they i need to parse them into their correct html entity :P
example using ur solution prints out:
e tan dif�cil como pensaba... Me ha costado casi un d�a
:S
thx anyway!