/    Sign up×
Community /Pin to ProfileBookmark

single quotes & double quotes and special characters insert into mysql

I have a php contact form where I can submit contact details. Now in textarea if I have a address that has “test” double quotes like that then it gives out an error when you submit it to be saved in database and then a mail will go . How can I make the double quotes or single quotes or any other character that is illegal to be inserted in mysql db to be saved in the mysql database without any error.

Thanks in advance

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@svidgenApr 01.2009 — Use something like mysql_real_escape_string() on [B]all[/B] of the submitted variables before interpolation into a query. This will not only allow proper insertion, but will also protect against simple injection attacks. You could even use a function to act iteratively [and recursively] on an array:

[code=php]function sanitize($v) {
if (is_array($v)) {
foreach ($v as $key => $value) {
$v[$key] = sanitize($value);
}
return $v;
} else {
return mysql_escape_string($v); // or some other [custom] function here.
}
} // sanitize()[/code]
Copy linkTweet thisAlerts:
@kavionlyauthorApr 01.2009 — Insertion is fine but in mail its taking slashes what is the problem?
Copy linkTweet thisAlerts:
@svidgenApr 01.2009 — Your first message indicated that you're getting errors upon attempted database insertion. If that's the case, my previous suggestion should solve the problem. If that's not the case, you need to provide more details about the problem. Perhaps you could post the specific error messages or log entries that indicate the problem.
Copy linkTweet thisAlerts:
@svidgenApr 01.2009 — Ohh ... do you mean the [I]escape*[/I] function is fixing insertion, but screwing up emailings???

If that's the case, you have a couple options. Either make an escaped [B]copy[/B] of the form data for database insertion and use the original for the mailing, or run [I]stripslashes()[/I] on the data for reusing in the mailing.
Copy linkTweet thisAlerts:
@kavionlyauthorApr 03.2009 — ok thanks its working fine
×

Success!

Help @kavionly 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 5.18,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...