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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:20:02+00:00 2026-06-04T04:20:02+00:00

I have a form and a user enters eg (note apostrophe at end of

  • 0

I have a form and a user enters eg (note apostrophe at end of string)

My Bday'

Now, I want to strip apostrophes, simple as that… not escape them, not add slashes just get rid of them

Firstly I have the following:

$event_title = mysql_real_escape_string($_POST['event_title']);

echo "<br /><br /><br />event title is $event_title";

Which results in the following being returned:

event title is My Bday\\\'

Why 3 slashes?

So, then I go ahead and deal with this by using the following:

$event_title = str_replace("'", "", $event_title); 

$event_title = stripslashes($event_title); 

Then I return it again to check results

echo "<br /><br /><br />event title is $event_title";

I get the following:

event title is My Bday\

Any ideas what’s happening? I simply want to strip apostophes and slashes but somehow it’s not happening

magic_quotes_gpc is off by the way

If I don’t use stripslashes therefore leaving them in for MySQL to deal with I get the following error:

You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'Private',
event_notes = '' where user_event_id = '35'' at line 3

update user_events set event_date = '2012-11-17', event_title = 'My Bday\\\',
event_vis = 'Private', event_notes = '' where user_event_id = '35'

OK, a further EDIT:

I tried this:

$event_title = $_POST['event_title'];

$event_title = str_replace("'", "", $event_title);

$event_title = trim($event_title);

$event_title = mysql_real_escape_string($event_title);

echo "<br /><br /><br />event title is $event_title";

and I get this:

event title is My Bday\\

I simply want to get rid of apostrophes, clearly something else is going on here but its got me!

  • 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-04T04:20:04+00:00Added an answer on June 4, 2026 at 4:20 am

    What’s happening is this:

    mysql_real_escape_string escapes all the characters that should be escaped by adding a slash in front of a character being escaped. But adding just a slash will lead to storing the character as unescaped within the DB, therefore also the slash must be escaped prior to inserting…

    That’s why You have My BDay\\\'. If this value is stored into a DB the final result will be My BDay\'.

    But when You do str_replace("'", "", 'My BDay\\\''); You will end up with My BDay\\\ and after calling stripslashes on this You will get My BDay\ – that is absolutely correct!

    So don’t bother with how the string looks like after calling mysql_real_escape_string, just store that value into the DB and after retrieving it You will end up with My BDay' again…

    EDIT How You come to just one slash from the three after calling stripslasshes? The function goes from the start of the string to its end and looks for any slash escaped characters to remove the escaping slash. So it finds first two slashes and removes one, but still two remains (the one just processed and the third one), so it processes next two slasshes it finds that will result in just one slash remaining…

    If You’d call stripslashes on the string My BDay\\\' – that will lead to My BDay'…

    EDIT2 My bad… The next two slashes are added probably because You have magic_quotes_gpc ON – turn that off or call mysql_real_escape_string(stripslashes($string)).

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

Sidebar

Related Questions

I have a simple form that uses jQuery validation to notify the user of
I have a form that requires a physical address. Once the user enters the
Right now I have a form where user enters the info. It is than
I have a form, user enters some data then submits. Rather than a popup
I have a jsp form validate.jsp which contains 2 text fields where user enters
I have a form where a user can enter the number of students that
I have a form that allows me to enter a user into my database.
I have a TextBox in a Windows Form that allows a user to enter
On my homepage I have a simple search form. The user can enter some
I have an HttpPost controller action that takes in a simple form DTO object.

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.