SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Wink problem entering/converting data into mysql

    Hi,

    My data has some unconverted characters like this in it,

    &-#39;

    I am using this set of functions for entering data in my mysql query,

    html_entity_decode(trim(mysql_real_escape_string(addslashes($pagename))))

    My problem is that the data doesnt get converted on the way into mysql

    It looks like this before going into mysql - &-#39;

    And it looks like this after it has been uploaded into mysql - &-#39;

    I thought that the above functions I am using were supposed to escape any problematic characters?

    Is it because this is an apostrophe? as i dont seem to have problems with other characters.

    Any help is much appreciated

    D

  2. #2
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    the ONLY function you should be using to insert data in to mysql is mysql_real_escape_string(). get rid of all the rest.

  3. #3
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Am i allowed to use those functions with the variables before the mysql query? or should i not be trimming my data,

    i am pulling it out of excel, so i suspect it needs trimming and i also have a lot of converted and unconverted characters etc, in my data that i am trying to normalise.

    am i going the wrong way about it?

    PS &-#39; is the converted code for an apstrophe " ' " could that be why it is causing problems? - I had to use the dash in between the & and # otherwise it wouldnt print in the message

    cheers

    d

  4. #4
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    does the excel file contain an actual apostrophe, or the html entity code for it?

  5. #5
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    does the excel file contain an actual apostrophe, or the html entity code for it?
    The excel file contains the entity code for an apostrophe which is &-#39; minus the dash.

    That is how it is ending up in my database, whereas i want it to be the converted apostrophe.

    any way of doing that?

    also does this mean that other uncoverted entities will do the same thing?

  6. #6
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    then you should be using mysql_real_escape_string(html_entity_decode($yourvariable))

  7. #7
    SitePoint Zealot
    Join Date
    Oct 2006
    Posts
    139
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried this and it didnt work, it seems its some weird problem i cannot work out

    I found this page and a function that really helped

    http://www.oreillynet.com/onlamp/blo..._latin1_t.html

    I know what he means about keeping everything in utf-8 at the end of his post

  8. #8
    reads the ********* Crier silver trophybronze trophy longneck's Avatar
    Join Date
    Feb 2004
    Location
    Tampa, FL (US)
    Posts
    9,854
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    you're going to have to provide some sample data. "some weird problem" is not enough for me to go on.


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
  •