How to strip_tags from mysql insert values

How would I go about stripping tags (and slashes) from mysql insert values in the provided example?

Is this a satisfactory security measure to prevent an injection attack?

$sql="INSERT INTO contact (fname, lname, email, phone, address1, address2, title, company, referrer, list, message)

Open in new window

LVL 16
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Marco GasiFreelancerCommented:
This should work:

$sql="INSERT INTO contact (fname, lname, email, phone, address1, address2, title, company, referrer, list, message)
VALUES('" . strip_tags($_POST[fname]) . "','" . strip_tags($_POST[lname]) . "','" . strip_tags($_POST[email]) ."','" . strip_tags($_POST[phone]) ."','" . strip_tags($_POST[address1]) . "','" . strip_tags($_POST[address2]) . "','" . strip_tags($_POST[title]) . "','" . strip_tags($_POST[company]) . "','" . strip_tags($_POST[referrer]) . "','" . strip_tags($_POST[list]) . "','" . strip_tags($_POST[message]) . "')";


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
s8webAuthor Commented:
Works great, thanks! I had to single quote around list though - strip_tags($_POST['list']) for some reason it came off the rails otherwise. It's a radio button, so I guess it's a variable?? I've been (only) a front end guy for so long... some of this mystifies me.

Thanks again!
Marco GasiFreelancerCommented:
Yes, sorry if if I didn't it but I had to go away urgently. list gives problem because it's a php function name so you have to enclose in quotes or use something like 'mylist'.

I'm glad to helped you. Thank you for points.
s8webAuthor Commented:
Got it,

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.