Tuesday, 29 November 2011

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:

Email:
Name:
Comments:



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



<% 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 %>

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


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.

http://www.aspwebpro.com/aspscripts/forms/formtodatabase.asp

No comments:

Post a Comment