Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 15th, 2005, 03:00 AM
Authorized User
 
Join Date: Mar 2005
Posts: 33
Thanks: 0
Thanked 0 Times in 0 Posts
Default Prevent SQL from crashing on user input

How can i protect my SQL queries from crashing/returning errors when users try to input characters that arent alpha numeric?

What should I do with the variable STR before concaternating it into the SQL string?

I want to be protected from any types of input.

HTML page:

...
 <form action="search.asp" method="POST">
 <input type="text" name="searchstring" />
 <input type="submit" value="Search" />
 </form>
...

ASP page:

...
 STR = Request.Form("searchstring")
 SQL = "SELECT * FROM Database WHERE text='"&STR&"';"
 SET RecordSet = Connection.Execute(SQL)
...

 
Old April 15th, 2005, 12:14 PM
Friend of Wrox
 
Join Date: Jan 2004
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

First of all in your HTML use Maxlength to limit number of charcters users can type in the searchstring,

<input type="text" name="searchstring" maxlength="30"/>

use VBScript replace function to escape apostrophe (')

STR = Replace(Trim(Request.Form("searchstring")),"'","'' )

I would recommend you use stored procedure along with ASP command object..
that way you do not have to worry about escaping or sql injection attack..





Similar Threads
Thread Thread Starter Forum Replies Last Post
prevent user logon and password from saving Hughesie78 ASP.NET 2.0 Basics 1 December 6th, 2007 12:20 PM
Displaying user input macrocosm Beginning PHP 3 June 15th, 2006 09:30 PM
Prevent user input while JS executes matty1stop BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 November 17th, 2005 10:35 AM
Validating user input stu9820 VB.NET 2002/2003 Basics 2 January 15th, 2004 12:51 PM
"Prevent User " javauniverse Pro VB Databases 3 January 9th, 2004 05:07 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.