Solved

encoding problems saving in mysql table

Posted on 2009-05-06
2
718 Views
Last Modified: 2013-12-12
I've had a bad night sleep over this... Can't figure out where it goes wrong.

in a form, the user is entering a field with e.g. "åäö" ,
a (AJAX) javascript is submitting it to a php file using POST submition and using encodeURIComponent
so the characters enter the php page like "%C3%A5%C3%A4%C3%B6" so far so good.
to insert this in the mysql database the php script translates this back with urldecode() (also tried rawurldecode) as far as i can see, the query send to the database contains the carachters "åäö" again. This is also as expected.

Now for the fun part;
when ik look in phpmyadmin what data is saved in the table i see:åäö as a value. NOT AS EXPECTED and certainly not wanted ;) if i display the table values in the front-end HTML page it also displays as: åäö.
If i on the other hand copy my query and paste it into phpmyadmin  and execute it, it all works out well, the åäö are saved properly. The AJAX javascript getting the values from the database in the backend messes up then but is step 2.

As far as i can see my database, tables and fields are encoded "latin1_swedish_ci"

now, where does this go wrong?
SNAG-0009.jpg
SNAG-0010.jpg
0
Comment
Question by:half-a-nerd
2 Comments
 
LVL 14

Expert Comment

by:shobinsun
ID: 24322851
Hi,

check your apache.conf  file for  AddDefaultCharset  variable.

If there is no , add AddDefaultCharset UTF-8.


And try again .hope this will help you.

Regards
0
 
LVL 3

Accepted Solution

by:
HMoellendorf earned 500 total points
ID: 24343296
Hello half-a-nerd,

thank you for posting at EE. It seems to be a charset problem. It is more better to convert the charset of the tables to utf8. Further, it could help to set the client_encoding after connecting to mySQL:

http://dev.mysql.com/doc/refman/5.1/en/charset-connection.html

Then it should work.

If you habe further questions let us know.

Kind regards,
Henning
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now