Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9019057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:41:08+00:00 2026-06-16T04:41:08+00:00

Possible Duplicate: Correct way to escape input data before passing to ODBC the error

  • 0

Possible Duplicate:
Correct way to escape input data before passing to ODBC

the error I am getting from querying a ODBC query is this:

(pos: 72 '...M = 'Owen O'^Donavon' AND...') - syntax error

and when I try to escape it:

(pos: 73 '... = 'Owen O\'^Donavon' AND...') - syntax error

the ^ means that is where it is breaking

I have tried the following:

NAM = '".$var."'

And also this:

NAM = '".mysql_escape_string($var)."'

then I got desperate

NAM = \"".$var."\"

Where $var is any name that contains a ‘ in it.

if you need the whole query:

UPDATE TABLE SET COLUMN1 = 'ERR' WHERE COLUMN_NAM = '".mysql_escape_string($var)."' AND COLUMN7 = 0");

does anybody know how I can get the quote properly escaped?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T04:41:09+00:00Added an answer on June 16, 2026 at 4:41 am

    To include a single quote within a MySQL string literal (which is delimited by single quotes), use two single quote characters. e.g.

    'I don''t like it'
    

    Effectively, When MySQL parses that, it will see the two single quote characters, and will interpret that as one single quote within a literal, rather than seeing the “end” of the string literal.

    But (as you are finding out) when you have only one single quote in there, the MySQL parser has a hissy fit over it. Consider this example:

    'I don't like it' 
    

    What the MySQL parser sees there is a string literal, five characters in length, containing 'I don'. Then MySQL sees that literal as being followed by some more tokens that need to be parsed: t like it. The parser does NOT see that as part of a string literal. That previous single quote marked the end of the string literal.

    So now, the MySQL parser can’t make heads or tails of what t like it is supposed to be. It sees the single quote following these tokens as the beginning of another string literal. (So, you could be very clever about what appears there, and manage to get something that MySQL does understand… and that would probably be even worse.)

    (NOTE: this issue isn’t specific to ODBC; this affects clients that make use of string literals in MySQL query text.)


    One way to avoid this type of problem is to use bind variables in your query text, vs. string literals. (But with MySQL, what’s happening anyway, is that escaping, what gets sent to the MySQL server (behind the scenes, so to speak) is a string literal.

    Sometimes we DO need to include string literals in our query text, and we shouldn’t be required to use bind variables as a workaround. So it’s good to know how to “escape” a single quote within a string literal which is enclosed in single quotes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Correct way to use scanf / printf (and family) with fixed size
Possible Duplicate: What's the correct way to test if a variable is a number
Possible Duplicate: What is the correct way of using extern for global variables ?
Possible Duplicate: What is the most accurate way to retrieve a user's correct IP
Possible Duplicate: What is the most accurate way to retrieve a user's correct IP
Possible Duplicate: Is there a way to instantiate objects from a string holding their
Possible Duplicate: Is there a way to have content from an IFRAME overflow onto
Possible Duplicate: Correct way of using JQuery-Mobile/Phonegap together? do I have to install jquery
Possible Duplicate: What is the easiest/best/most correct way to iterate through the characters of
Possible Duplicate: What is the correct way to create a single instance application? How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.