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 7945149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:46:24+00:00 2026-06-04T00:46:24+00:00

I was reading Does $_SESSION['username'] need to be escaped before getting into an SQL

  • 0

I was reading Does $_SESSION['username'] need to be escaped before getting into an SQL query? and it said “You need to escape every string you pass to the sql query, regardless of its origin”. Now I know something like this is really basic. A Google search turned up over 20, 000 results. Stackoverflow alone had 20 pages of results but no one actually explains what escaping a string is or how to do it. It is just assumed. Can you help me? I want to learn because as always I am making a web app in PHP.

I have looked at:
Inserting Escape Characters, What are all the escape characters in Java?,
Cant escape a string with addcslashes(),
Escape character,
what does mysql_real_escape_string() really do?,
How can i escape double quotes from a string in php?,
MySQL_real_escape_string not adding slashes?,
remove escape sequences from string in php I could go on but I am sure you get the point. This is not laziness.

  • 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-04T00:46:26+00:00Added an answer on June 4, 2026 at 12:46 am

    Escaping a string means to reduce ambiguity in quotes (and other characters) used in that string. For instance, when you’re defining a string, you typically surround it in either double quotes or single quotes:

    "Hello World."
    

    But what if my string had double quotes within it?

    "Hello "World.""
    

    Now I have ambiguity – the interpreter doesn’t know where my string ends. If I want to keep my double quotes, I have a couple options. I could use single quotes around my string:

    'Hello "World."'
    

    Or I can escape my quotes:

    "Hello \"World.\""
    

    Any quote that is preceded by a slash is escaped, and understood to be part of the value of the string.

    When it comes to queries, MySQL has certain keywords it watches for that we cannot use in our queries without causing some confusion. Suppose we had a table of values where a column was named “Select”, and we wanted to select that:

    SELECT select FROM myTable
    

    We’ve now introduced some ambiguity into our query. Within our query, we can reduce that ambiguity by using back-ticks:

    SELECT `select` FROM myTable
    

    This removes the confusion we’ve introduced by using poor judgment in selecting field names.

    A lot of this can be handled for you by simply passing your values through mysql_real_escape_string(). In the example below you can see that we’re passing user-submitted data through this function to ensure it won’t cause any problems for our query:

    // Query
    $query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
                mysql_real_escape_string($user),
                mysql_real_escape_string($password));
    

    Other methods exist for escaping strings, such as add_slashes, addcslashes, quotemeta, and more, though you’ll find that when the goal is to run a safe query, by and large developers prefer mysql_real_escape_string or pg_escape_string (in the context of PostgreSQL.

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

Sidebar

Related Questions

How does performance for reading/adding values from/to Dictionary(Of String, SomeReferenceType) depend on the number
I was reading an article about how query expressions defer executions. Does that mean
Why does reading from __DATA__ work and reading from the file doesn't (Loose unescaped
When learning new languages such as C++ from PHP, does reading other language snippets
Does anyone know how to adjust the iPhone's compass reading to adjust if you
Does anyone know if there is a builtin function for reading from the console
I was just reading this line: The first thing the format() method does is
I've been reading a lot about how Scala and Erlang does lightweight threads and
I was reading about IDN homograph atack and didn't find exactly stated does browsers
While I'm busy here reading the FastCGI documentation (yeah, reading the 'friendly' manual), does

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.