SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Hybrid View

  1. #1
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    symbol getting entered as "£24.00"

    Hi Guys!

    I have a website where users enter a salary into a field and then it gets entered into the MySQL database. If I enter 75k it should get entered into the database as 75k. However, it's getting entered as £75k.

    The doctype on the page is utf8
    Code:
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    The database field is also utf-8
    Code:
    job_salary 	varchar(200) 	utf8_general_ci 		Yes 	NULL
    I have really run out of ideas what may be causing this. It must be something on the frontend, as i'm using the same code on other websites and all work fine.

    Any ideas?

  2. #2
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    You should set the charset using a header as well, since the meta tag is only used if a header does not exist.

    Try to add:
    header('Content-Type: text/html; charset=utf-8');

    Edit:
    Seems I might have misunderstood the question, are you saying it get entered into the database as such?

    If, have you checked that you are running the connection to the database as utf8?

    You might want to try this before you run the query if not:
    mysql_query('SET NAMES utf8') or die(mysql_error());

  3. #3
    SitePoint Wizard Zaggs's Avatar
    Join Date
    Feb 2005
    Posts
    1,048
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, that seems to have fixed it. However, I just noticed on the other sites (where it is working) that the is also stored as £ in the database - yet on the frontend when the information is displayed, only the symbol shows (which is correct). I am not using any utf-8 decoding when getting the results from the database either. No idea whats going on here...

    Any ideas?

  4. #4
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,196
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Most probably the "incident" is a result of different server settings on the web sites.

    Which has helped with the previous systems for example is setting the web server charset to UTF-8 or/and the database also doing the same automatically.

    If your code is to be deployed on multiple systems that you do not have absolute control on the server settings, I would recommend setting the code up with both sending a charset header and always setting the database connection to the correct charset.

  5. #5
    SitePoint Member
    Join Date
    Dec 2010
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just wondering, what software do you use to "see" the data stored in MySQL? Could be something wrong with in that software.

  6. #6
    SitePoint Member
    Join Date
    Mar 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know how to set the database connection with the correct charset, but how do you send a charset header? Is that in the header for the page? I'm not sure what header is being referred to. Thanks!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •