SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Zealot dadofgage's Avatar
    Join Date
    Feb 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Unhappy Postgres and characters from MSWord causing problems on insert/update

    Okay, I have a client that has been running a web application on a codebase for a couple of years without any kind of problems.

    This site is created in PHP, Smarty Templates, ADODB and a Postgres database.

    I have started to receive a number of help requests from them because of errors that are now popping up in regarding to people trying to insert data into the database via the forms on the website.

    Here is a sample sentence that is causing an error:

    'The Jury Clerk is responsible for the work of the District Clerk’s Office in connection with qualifying, managing, and paying jurors for service.'

    Now, I know tha tthe problem is with the apostrophe in the word 'Clerks'.

    Here is our insert statement:

    $sql = "INSERT INTO table_name (col1, col2, col3) VALUES (?,?,?)";
    $db->Execute($sql, array($var1, $var2, $var3)) or die("Error in query: $sql. " . $db->ErrorMsg());

    Okay, this has never been a problem until we found out that people were using Microsoft Word 2007 to create the text that they were going to enter into the website and then copy and paste it into the web form.

    Can anyone shed light on why if I manually type this information into the form, the form works as expected, but if I copy it from Word 2007 - it fails?

  2. #2
    SitePoint Evangelist
    Join Date
    Aug 2007
    Posts
    566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Because even it's it looks similar, Word don't use Ascii characters.
    I suspect that it uses an utf-8 charset, and that your DB collation is set to ascii.
    Here is an ascii character table, if needed:
    http://www.cse.unsw.edu.au/~cs3221/AVR/ascii.bmp

    If you try to dump your form values with an ord(character), you will see that the ascii value is different of the regular single quote.
    In the past, I finished with a "cleanup" function that was replacing those characters with their equivalent in ascii.

  3. #3
    SitePoint Zealot dadofgage's Avatar
    Join Date
    Feb 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks.

    What was strange to me is that it was only happening in Word2007 characters and not others.

    But your answer did push me in the right direction and I was able to get a solution in place.

  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)
    Quote Originally Posted by dadofgage View Post
    What was strange to me is that it was only happening in Word2007 characters and not others.
    that's not strange at all. microsoft word is for typography, not code development. it silently replaces your quotes with "fancy" quotes for readability. do yourself a favor and get a real code editor.
    Check out our new Industry News forum!
    Keep up-to-date with the latest SP news in the Community Crier

    I edit the SitePoint Podcast

  5. #5
    SitePoint Zealot dadofgage's Avatar
    Join Date
    Feb 2005
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by longneck View Post
    that's not strange at all. microsoft word is for typography, not code development. it silently replaces your quotes with "fancy" quotes for readability. do yourself a favor and get a real code editor.

    Sorry if I was clear about the problem.

    End users were copying and pasting from Word - I was not trying to code the site or anything in Word - I'm not that stupid.

    Maybe you should read the thread that a solution was found and that we didn't your idiotic, 'better than you' answer.


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
  •