Web Design Forum  
 
Go Back   Web Design Forum > Web Software > Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 03-14-2005, 03:22 AM   #1 (permalink)
Super Noob
 
zkiller's Avatar
 
Join Date: Aug 2004
Location: position:relative
Posts: 1,461
Send a message via AIM to zkiller Send a message via Yahoo to zkiller
Default apostrophes and sql

well, in asp you can have a user put a apostrophe in a field as it will recognize it as being the end of a field and create an error. however there are ways around this. since i am lazy, i decided to search for a function to take care of this little problem for me instead of writting my own. i found one which i liked and promptly integrated it. it works great on all fields of the user profile on our site, but two. i am to tired to figure it out right now as to why it's not working... maybe tomorrow. :shrug: anyways, just thought i would share. someone on sitepoint forums posted this.

function:
Code:
	Public Function CleanQuotes( ByVal strDirty, boolRemove )
		strData = Replace( Replace( strDirty, Chr(147), Chr(34) ), Chr(148), Chr(34) )
		strData = Replace( Replace( strData, Chr(146), Chr(39) ), Chr(96), Chr(39) )
		If Not CBool( boolRemove ) Then
			strData = Replace( strData, Chr(39), String( 2, Chr(39) ) )
			strData = Replace( strData, Chr(34), Chr(39) & Chr(34) )
		ElseIf CBool( boolRemove ) Then
			strData = Replace( strData, Chr(39), Chr(32) )
			strData = Replace( strData, Chr(34), Chr(32) )
			Do While InStr( 1, strData, String( 2, Chr(32) ) ) > 0

				strData = Replace( strData, String( 2, Chr(32) ), Chr(32) )
			Loop
		End If
		CleanQuotes = Trim( strData )
	End Function
example for using it:
Code:
	' to escape for SQL statements
	strClean = CleanQuotes( strDirtyData, False )
	' to remove completely
	strClean = CleanQuotes( strDirtyData, True )
__________________
Stefan, the Post Master

Track Devil - May the boost be with you!
zkiller is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:37 AM.


Computer Forum - Internet Business - Webpage Design

 
Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.