Form to Database ASP Script - ASP Web Pro
  Active Server Pages Programming by ASP Web Pro

ASP Scripts

INSERT FORM DATA TO DATABASE

When a user submits a contact form, it is a good idea to record a copy of that email into a database for future reference. Here is how you can do it with MS Access.

The first thing you need to do is create a formpage.asp page with the code below:

<form name="YourFormName" method="Post" action="resultspage.asp">
<table>
<tr><td>Email: </td>
<td><input type="text" name="Email" size="50"></td></tr>
<tr><td>Name: </td>
<td><input type="text" name="Name" size="50"></td></tr>
<tr><td>Comments: </td>
<td><textarea name="Comments"></textarea></td>
</table>

<input type="submit" name="Submit" value="Submit Form">
</FORM>

Next, we create a resultspage.asp page and enter the code as seen below:

<!--#INCLUDE VIRTUAL="/includes/connection.asp" -->

<%
DIM objRS
Set objRS = Server.CreateObject("ADODB.Recordset")
objRS.Open "YOUR table name HERE", objConn, , adLockOptimistic, adCmdTable

objRS.AddNew
objRS("Email") = Request.Form("Email")
objRS("Name") = Request.Form("Name")
objRS("Comments") = Request.Form("Comments")
objRS.Update

objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
%>

<p>
<%
DIM strName
strName = Request.Form("Name")
Response.Write strName
%>,</p>

<p>Thank you for emailing me.</>

Now you have a complete form that sends data to database that you can refer to in the future. This is a great way to follow up with customers and track how many people are using your website from year to year.

< Back to ASP Scripts


 

 

Main Menu
Home
ASP Scripts
ASP Tutorials
JavaScripts
Awards
Contact Us

Email This Page

Other Resources
ASP Web Hosting
Search Engine Submission
Programming Help

 

 

 

Other ASP Web Sites

Site Map

 

Last Updated:
13 May 2008