0

I have a form that asks for a name. The php to process it is:

$name = mysqli_real_escape_string($dbc, trim($_POST['name']));

When someone inserts a name with an apostrophe e.g. Dan O'Shea it shows up in the mysql database fine, but on the webpage it's output shows up as Dan O\Shea.

How do I get rid of the \ backslash and show the ' apostrophe on the webpage? Can I use str_replace('/','', $string) with mysqli_real_escape_string, and if so how?

Thanks for any help,

Andy ;-)

2 Answers 2

1

use stripslashes() to remove extra backslashes.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks joaofgf, is that with or without the mysqli_real_escape_string?
with mysqli_real_escape_string()
@AndyR Use it when you're showing the data in the page. stripslashes($row['name']);
Hi Zerquix18 and joaofgf, when using the localhost I don't have the problem, it's only on a free hosting account that it occurs. So are they being extra cautious or what?
your hosting provider has gpc_magic_quotes enabled and your local server doesn't.
0

Sounds like you have gpc_magic_quotes turned on.

http://php.net/manual/en/security.magicquotes.php

2 Comments

Thanks Andy. The problem is not on my localhost - it works fine there. The problem seems to arise only when I put the code up on a free hosting provider. Eventually I will go with paid hosting once the site is complete, I am just testing and found this problem. Is this common? Thanks again Andy ;-)
I don't know how common things may be. I only work with servers that I admin directly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.