SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: weird chars stored into database

  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question weird chars stored into database

    Hello

    I'm developing a website written in PHP
    the website uses MySQL to store data

    the website is developed mainly with dreamweaver, and handcoded where necessary

    when I send data from a form to the database, if the content of the form field (textarea) contains chars like èòàùì they're written to the database as è, ò, à ,ù and visualized in html pages as little squares

    the database field where this text is stored is a text field, latin1_swedish_ci (hence if I'm correct it should support òàùèì)
    I have tried with utf8_unicode_ci as well, no difference

    if I print those chars on the page before executing the insert they are ok, it seems like the are 'corrupted' while being sent to the database

    the page where I fill the form is UTF-8

    any ideas?

  2. #2
    Jewish Juggernaut mkoenig's Avatar
    Join Date
    Aug 2007
    Posts
    1,227
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    May be your character set, but may also be that you are copy and pasting from Word or something similar.

    that always gives me strange characters.

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2008
    Posts
    191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You can delimit unsupported characters using this code.

    Code:
    if(!ereg('^[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+'. '@'.'[-!#$%&\'*+\\/0-9=?A-Z^_`a-z{|}~]+\.'.'[-!#$%&\'*+\\./0-9=?A-Z^_`a-z{|}~]+$',$inserttextintodb))
       {
          echo 'unsuported characters.';
       }
    else
    {
    mysql_query('INSERT INTO ........');
    }

  4. #4
    SitePoint Zealot falsealarm's Avatar
    Join Date
    Sep 2008
    Posts
    147
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe the declaration on the page, code and database need to match for the foreign character displays to work as expected. A script that I was running gave me some headache sometime ago and this was the case. You just need to make sure that all parts play on the same characterset

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
  •