BPSoftware.com
Home   Utilities   Purchase   FAQ   Support   Contact        
Shareware Utilities
 APrintDirect
 AIconExtract
 AFile Attribute Manager
Freeware Utilities
 AddrMon
 AFileSync
 ASysIcon
 B&P Table Utilities
 BPACLer
 BPSNMPMon
 BPSNMPUtil
 CharCount
 Delphi® Components
 MacAddr
Miscellaneous
 BPSoftware Blog
 Purchase Shareware
 Support

 Subscribe!

Saturday, August 26, 2006
Classic ASP and a Form

Forms are a common way to collect data on websites. A form can be made up of a number of controls; it is the input controls are used to collect user input. Once a user fills out a form there something is usually done with the data. I often save the information to a database. Instead of scripting out and insert statement you can easily pass ‘loop’ through each of the field values and build a statement. This would assume the field names in the database table match those of the input field names on the form.
<%
STR_SQL= "INSERT INTO data ("
STR_VALUES = "VALUES ('"
For each inputField in Request.Form
STR_SQL = STR_SQL & inputField & ", "
For each inputValue in Request.Form(inputField)
STR_VALUES = STR_VALUES & inputValue & "', '"
Next
Next

STR_SQL = STR_SQL & "REMOTE_ADDR, Date_Time) "
STR_VALUES = STR_VALUES & Request.ServerVariables("REMOTE_ADDR") & "', '" & Now() & "')"

STR_SQL= STR_SQL & STR_VALUES

‘DataConn is an existind data connection and post_RS is a recordset
Set post_RS = DataConn.Execute(STR_SQL)
%>

You could also list the information on the POST page:
<%
For each inputField in Request.Form
For each inputValue in Request.Form(inputField)
Response.write(inputField & “: “ & inputValue)
Next
Next

%>

Labels: ,

posted by Brad Prendergast at 6:25:00 PM
Comments:
Links to this post:

Create a Link

Recent Posts
 Ye Old TFileEdit
 TypInfo is cool!
 A bit, byte and word
 Having a little fun and getting a Callback
 Too much?
 Virtual PC Is Now Free!
 Who does not like cookies?
 DayLightTime
 A tale of ASP, Excel and a RecordSet
 Conversion Utility

 Subscribe!


Labels



Archives
 October 2005
 November 2005
 December 2005
 January 2006
 February 2006
 March 2006
 April 2006
 May 2006
 June 2006
 July 2006
 August 2006
 September 2006
 December 2006
 January 2007
 February 2007
 March 2007
 September 2007
 October 2007
 November 2007
 July 2008
 November 2008
Powered by Blogger