26334 total geeks with 3498 solutions
Recent challengers:
 Welcome, you are an anonymous user! [register] [login] Get a yourname@osix.net email address 

Articles

GEEK

User's box
Username:
Password:

Forgot password?
New account

Shoutbox
MaxMouse
It's Friday... That's good enough for me!
CodeX
non stop lolz here but thats soon to end thanks to uni, surely the rest of the world is going good?
stabat
how things are going guys? Here... boring...
CodeX
I must be going wrong on the password lengths then, as long as it was done on ECB
MaxMouse
lol... the key is in hex (MD5: of the string "doit" without the "'s) and is in lower case. Maybe i should have submitted this as a challenge!

Donate
Donate and help us fund new challenges
Donate!
Due Date: Jun 30
June Goal: $40.00
Gross: $0.00
Net Balance: $0.00
Left to go: $40.00
Contributors


News Feeds
The Register
Google joins
Amazon, HP,
Rackspace in easing
HDD data importing
Adobe CEO admits
needs to "tweak"
cloud-only policy
John McAfee
releases NSFW video
on how to uninstall
security code
Speaking in Tech:
We find someone who
hasn"t heard of
Prof Brian Cox
Dish abandons
Sprint sprint, now
in mad dash for
Clearwire
You"re still hired:
Viglen bosses get
to keep jobs for
another year
Nutanix trims down
and fattens up
server-storage
halfbloods
Stay away from the
light, Kodak! Look,
here"s $406m to
keep you alive
Oracle: We WON grey
market software and
Solaris support
case
Dynamo-spawn Riak
spreads to other
clouds
Slashdot
Millions At Risk
From Critical
Vulnerabilities
From WordPress
Plugins
Ubuntu Phone
Carrier Advisory
Group Announced
Cumulus Releases
GNU/Linux For
Datacenter Routers
Relicensing of
MySQL Man Pages
Just a Bug
BT Chief To Become
British Government
Minister
One Year Since
Assange Took Refuge
in Ecuadorian
Embassy
Subversion 1.8
Released But Will
You Still Use Git?
Google Patents
Image-Capturing
Walking Sticks
PDP-11 Still
Working In Nuclear
Plants - For 37
More Years
NSA"s Role In
Terror Cases
Concealed From
Defense Lawyers
Article viewer

Sending special characters to MSSQL



Written by:sliptop
Published by:SAJChurchey
Published on:2005-10-05 19:26:49
Topic:PHP
Search OSI about PHP.More articles by sliptop.
 viewed 14217 times send this article printer friendly

Digg this!
    Rate this article :
Are you getting tired with struggling to send a single quote to the database from a large amount of posted variables? This small code snippet loops through all _POST vars and then strips the php added slashes, and adds an escape char to the _POST var.

You can also substitute _POST for _GET or _REQUEST if you want to change the type of input check.

foreach($_POST as $key => $value)
{
$value = str_replace("'","''",$value);
$value = stripslashes($value);
$_POST[$key] = $value;
}


This is different from what you see on the php doc help. Because you are changing the key value, not just the value (a ref type) you are actually changing the value of the array var. This code can be easily modified to loop through just about any array you like, but this is a nice snippet to add into a more complex input filter for forms etc, anything that interacts with a MSSQL db (Can be used with other SQL db's too). Of course different versions of PHP will vary slightly, so just check the slashes policy stuff with php.net.

Enjoy.

Did you like this article? There are hundreds more.

Comments:
bb
2005-10-06 12:54:40
ive never had to do this in any php code. sure your not mental?
Domuk
2005-10-06 18:17:00
It depends on the options. However, I believe there's a specific option to set that will parse everything as if it was being passed into an MSSQL db, which should sort all this out. Never used it, though, so if there's an actual set of functions for MSSQL dbs, I guess it would do that anyway.
MikeSherman
2009-07-29 11:34:11
Possibly you are referring to Magic Quotes, a now deprecated setting which if set to on ran addslashes() on all POST, GET, COOKIE data automatically:
http://uk.php.net/manual/en/security.magicquotes.php
Anonymously add a comment: (or register here)
(registration is really fast and we send you no spam)
BB Code is enabled.
Captcha Number:


Blogs: (People who have posted blogs on this subject..)
elasolova
My PHP Projects on Sat 26th Sep 10am
I have been developing PHP applications for almost a year now. I have developed three projects. One is a simple trivia game. The other is a question-answer based community at http://www.javaist.com/quans . The last one is a programming challenge site just
countll
Blog entry for Thu 25th Oct 7am on Thu 25th Oct 7am
soo nu on this wicked world of NET. just decided to dive in today..hope friend aroun here can help

Test Yourself: (why not try testing your skill on this subject? Clicking the link will start the test.)
Test of experience (hopefully) by AcidIce

Things you're only likely to know if you've actually written a lot of PHP before :)


     
Your Ad Here
 
Copyright Open Source Institute, 2006