MSSQL Insertion problem....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ghadacr
Forum Contributor
Posts: 135
Joined: Fri May 11, 2007 10:44 am

MSSQL Insertion problem....

Post by ghadacr »

Right folkes,

The problem lies here, the insertion of data into the database works fine, when i started to do some testing and enter a piece of data with ' in use i get the following error message:
Warning: mssql_query() [function.mssql-query]: message: Line 1: Incorrect syntax near '1'.
If any one is got some PHP code to solve this issue will be most welcomed, thanks in advance....
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

use addslashes() on the data where you are expecting '.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Be aware that there are ways of bypassing addslashes()' escapement routines in some (maybe all) versions of PHP.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Does mssql not have an escape_string function?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Not natively.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

There is little development on the mssql/sybase family of functions. I think PDO has an escape functionality for each RDBMS, but you would need to install the PDO extensions and have the PDO drivers installed before using it.

You could always write your own escape tool.
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

feyd wrote:Be aware that there are ways of bypassing addslashes()' escapement routines in some (maybe all) versions of PHP.
Can you please elaborate this?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

mentor wrote:Can you please elaborate this?
Sure. Thread posted by Chris Shiflett titled "Fun with addslashes()" viewtopic.php?t=43203
mentor
Forum Contributor
Posts: 100
Joined: Sun Mar 11, 2007 11:10 am
Location: Pakistan

Post by mentor »

Thanks feyd.
Post Reply