Mysql problem with ñ and Ñ - SOLVED

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

Mysql problem with ñ and Ñ - SOLVED

Post 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?
Last edited by deeessay on Sat Sep 13, 2008 2:47 am, edited 1 time in total.
BETA
Forum Commoner
Posts: 47
Joined: Fri Jul 25, 2008 3:21 am

Re: Mysql problem with ñ and Ñ

Post 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!
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Re: Mysql problem with ñ and Ñ

Post 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.
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

Re: Mysql problem with ñ and Ñ

Post 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...
User avatar
deeessay
Forum Commoner
Posts: 55
Joined: Sat May 24, 2008 1:02 am

Mysql problem with ñ and Ñ -- SOLVED

Post 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' />
BETA
Forum Commoner
Posts: 47
Joined: Fri Jul 25, 2008 3:21 am

Re: Mysql problem with ñ and Ñ - SOLVED

Post 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!
Post Reply