PHP Error Character (HELP!)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • werks
    New Member
    • Dec 2007
    • 218

    PHP Error Character (HELP!)

    Hello PHP experts how can you detect ' character in your search field?
    Because every time I input the word hilgard's it returns an error I think because of the character '. This is the error

    [CODE=php]
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Title LIKE '%hilgard's%';' ., SQL state 37000 in SQLExecDirect in D:\wamp\www\Onl ine Library\opac.ph p on line 76
    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Title LIKE '%hilgard's%';' .
    [/CODE]

    tnx in advance.

    --
    Kenneth
    "Better Than Yesterday"
  • dlite922
    Recognized Expert Top Contributor
    • Dec 2007
    • 1586

    #2
    Originally posted by werks
    Hello PHP experts how can you detect ' character in your search field?
    Because every time I input the word hilgard's it returns an error I think because of the character '. This is the error

    [CODE=php]
    Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Title LIKE '%hilgard's%';' ., SQL state 37000 in SQLExecDirect in D:\wamp\www\Onl ine Library\opac.ph p on line 76
    [Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression 'Title LIKE '%hilgard's%';' .
    [/CODE]

    tnx in advance.

    --
    Kenneth
    "Better Than Yesterday"
    Its about time you know about a little some'n some'n called


    After you studied it, then do learn how to prevent it:



    Only you have MS SQL and not MySQL, but you get the point.

    If you're still not satisfied.

    Just use string replace

    Replace all occurrences of the search string with the replacement string


    [PHP]
    str_replace("'" , "\'", $sqlString);



    [/PHP]

    Get it?, got it?, gooOOood!

    Comment

    • werks
      New Member
      • Dec 2007
      • 218

      #3
      Thanks dlite922 I learned a lot! All the links you post is very useful. Than you very much..

      --
      Kenneth
      "Better Than Yesterday"

      Comment

      Working...