/    Sign up×
Community /Pin to ProfileBookmark

Stripping apostrophes from emails

Hello,

I’m trying to strip ‘ from my emails, so that when I log them in my database, it won’t mess up the SQL query.

I’ve got a varaible for the textarea of my form:

$comments = $_POST[‘comments’];

preg_replace(“#’#”, “”, $comments);

then it INSERTS INTO the database.

If it doesn’t work, the email is not sent and an error is displayed.

But this does not work. Should I use the trim function with the charlist parameter? I’m really out of ideas.

Thanks for any help,

Michael.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@SheldonJun 11.2007 — [code=php]
$comments = addslashes($_POST['comments']);[/code]
Copy linkTweet thisAlerts:
@invisionauthorJun 11.2007 — Crikey. That was it! ?

Thanks very much.
Copy linkTweet thisAlerts:
@SheldonJun 11.2007 — No worries.
Copy linkTweet thisAlerts:
@andre4s_yJun 11.2007 — There is more simple way to do... ?

Just "on" the magic_quotes_gpc in the php.ini.

That magic_quote will automatically escape(add backslash) the single quote, double quote, backslash, and NULL.

you can try this if you have enough time to play with php..

hehehehe otherwise, sheldon's code is incredible...

There is other function to escape the single quote. You can use htmlspecialchars function or htmlentities function. And if you use mysql, you can user mysql_real_escape_string() function.

Happy coding..

regard,

Andre
×

Success!

Help @invision spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...