using apostrophe in sql statement

This is a discussion on "using apostrophe in sql statement" within the Classic ASP section. This forum, and the thread "using apostrophe in sql statement are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > Classic ASP

Notices


Reply
 
LinkBack (1) Thread Tools
  1 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old Oct 5th, 2006, 13:44
Junior Member
Join Date: Dec 2005
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
using apostrophe in sql statement

I'm having an error with my ASP page when a person puts an apostrphe into a field to be entered into a sql database.. here is a test on the sql statement:

SELECT * FROM tblRequests WHERE firstname="Test" AND lastname="Test'O" AND checktype="Bankruptcy" AND dateEntered="10/5/2006"

here is the code that puts it together:

Code: Select all
  newSQL="SELECT * FROM tblRequests WHERE firstname=" & Chr(34) & MBRequest("txtFirst") & Chr(34) & ""
  newSQL=newSQL & " AND lastname=" & Chr(34) & MBRequest("txtLast") & Chr(34) & ""
  newSQL=newSQL & " AND checktype=" & Chr(34) & Session("CheckType") & Chr(34) & ""
  newSQL=newSQL & " AND dateEntered=" & Chr(34) & FormatDateTime(now(),2) & Chr(34) & ""
The error I get is this:

Microsoft OLE DB Provider for ODBC Drivers error '80040e21'
ODBC driver does not support the requested properties.
/secur-it/background/submitorder.asp, line 125


can anyone help me out with this?
Reply With Quote

  #2 (permalink)  
Old Oct 10th, 2006, 13:09
Junior Member
Join Date: Sep 2003
Location: Dubai, United Arab Emirates
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Re: using apostrophe in sql statement

you need to escape all single quotes with another single quote as bar minimum

So

Denis O'Reilly

becomes

Denis O''Reilly

(with two single quotes instead of one single quote).

Use a function that does a replace... e.g.

Function SQLSafe(strText)
SQLSafe = Replace(strText, "'", "''")
End Function

Then you can put SQLsafe(xxx) around whatever values you link into your SQL query

Failing to sanitize scripts like this is more dangerous than you think. Google for SQL injection and prepare to cr4p your pants.
Reply With Quote
Reply

Tags
sql statements

Thread Tools

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

LinkBacks (?)
LinkBack to this Thread: http://www.webforumz.com/classic-asp/9307-using-apostrophe-in-sql-statement.htm
Posted By For Type Date
Web Design Forums - Web design and development help and discussion This thread Refback Oct 7th, 2006 21:18

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP If Statement... mcdanielnc89 PHP Forum 16 Dec 9th, 2007 17:44
How to include font name that has apostrophe Lchad PHP Forum 3 Sep 17th, 2007 16:30
apostrophe becomes ’ aaronh Web Page Design 12 Jul 30th, 2007 13:38
Apostrophe in Text Output RobinDeanDotCom PHP Forum 2 Oct 4th, 2006 12:48
Apostrophe... Lizard- Classic ASP 2 Aug 13th, 2004 13:11


All times are GMT. The time now is 06:25.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43