<% Option Explicit ' Form processer for eCommerce projects ' <% ... %> - code inside these marks is processed and removed by asp processor ' Inside <% ... %>, ' starts a comment that is ignored by the asp processor ' Below, change names to match your fields and database ' For info in square brackets [ ] - do not include the brackets %> Order Confirmation - David's Sugar-Free Sweets <% ' Start asp section ' *************************** This means a BIG MAIN section ' Put information in database ' *************************** ' "Option Explicit" means that any parameter must first appear in a "Dim" ' statement - this can be a pain but catches typos. Dim cnConnect ' The connection to the database Dim rsOrder ' The record for this order Dim fld ' A field in the record, cycles through all fields Dim FieldName ' The field name for fld Dim FieldValue ' The field value for fld Dim adOpenKeyset ' A detail of the connection to the database Dim adLockPessimistic ' A detail of the connection to the database adOpenKeyset = 1 adLockPessimistic = 2 ' Calculate the cost information from the form information, for example ' Here, we imagine that the user can order from three choices in the catalog Dim SubTotal_1 ' We will calculate this as the cost of the first item Dim SubTotal_2 ' We will calculate this as the cost of the second item Dim SubTotal_3 ' We will calculate this as the cost of the third item Dim Number_1, Number_2, Number_3 ' Quantity ordered Dim Cost_1, Cost_2, Cost_3 ' item unit cost (cost for one) Dim TotalCost ' We will calculate this as the total cost of the order Number_1 = Request("Number_1") ' Transfer data from the form (Request) Number_2 = Request("Number_2") Number_3 = Request("Number_3") Cost_1 = Request("Cost_1") Cost_2 = Request("Cost_2") Cost_3 = Request("Cost_3") SubTotal_1 = Number_1 * Cost_1 SubTotal_2 = Number_2 * Cost_2 SubTotal_3 = Number_3 * Cost_3 TotalCost = SubTotal_1 + SubTotal_2 + SubTotal_3 ' End of calculation ' -------------------------- This means a sub-section ' MAKE CONNECTION TO DATABASE Set cnConnect = Server.CreateObject("ADODB.Connection") cnConnect.ConnectionString = "DSN=[Your DSN]" cnConnect.Open ' ----------------------------- ' CREATE AND OPEN THE RECORD FOR THIS ORDER Set rsOrder = CreateObject("ADODB.RecordSet") rsOrder.CursorLocation = 3 ' adUseClient or client-side cursor rsOrder.Open "[Your table]", cnConnect, 2, 3 ' --------------------------- ' ADD NEW RECORD TO RECORDSET rsOrder.AddNew ' Populate the database fields by looping over them, For to Next For each fld in rsOrder.Fields FieldName = fld.Name If (FieldName = "Order_Number") Then ' Do nothing - autonumber ' Date and time come from the server clock ElseIf (FieldName = "Date") Then rsOrder.Fields("Date") = FormatDateTime(Now, vbShortDate) ElseIf (FieldName = "Time") Then rsOrder.Fields("Time") = FormatDateTime(Now, vbShortTime) ' Information calculated in the script must be put in item by item ElseIf (FieldName = "Status") Then rsOrder.Fields(FieldName) = "Received" ElseIf (FieldName = "SubTotal_1") Then rsOrder.Fields(FieldName) = SubTotal_1 ElseIf (FieldName = "SubTotal_2") Then rsOrder.Fields(FieldName) = SubTotal_2 ElseIf (FieldName = "SubTotal_3") Then rsOrder.Fields(FieldName) = SubTotal_3 ElseIf (FieldName = "TotalCost" rsOrder.Fields(FieldName) = TotalCost ' Information from the form goes in easily Else FieldValue = Request(FieldName) rsOrder.Fields(FieldName) = FieldValue End If Next ' End of loop ' Transfer order data from recordset to database ' and transfer the order number from database to recordset rsOrder.Update ' ******************************************************** ' Prepare the response page, will be sent at end of script ' All regular HTML (outside of <% ... %>) is for response page ' Also, all <%= goes in response page ' ******************************************************** %>

This is your printable confirmation:

<% For each fld in rsOrder.Fields FieldName = fld.Name FieldValue = rsOrder.Fields(FieldName) %> <% Next %>
<%=FieldName%> <%=FieldValue%>


We will send a confirming email shortly.

Link back to Our home page

<% ' ****************** ' Now send the Email ' ****************** Dim objMail ' The email message Dim strMessage ' The message content Dim strName ' The sender's regular name Dim intEmailOK ' = 1 for Sender's email OK - assumed OK here Dim strSubject ' The topic of the email message Dim strReceive ' To address Dim strSender ' The From email address strReceive = Request("[Email]") ' Customer's email address, must match name of field in form strSender = "[Your WSU email address]" strSubject = "Your order from [your company name here]" ' Construct the message strMessage = "" For each fld in rsOrder.Fields FieldName = fld.Name FieldValue = rsOrder.Fields(FieldName) strMessage = strMessage & FieldName & ": " & FieldValue & vbNewLine ' "&" means "concatenation" - butt text together Next Set objMail = Server.CreateObject("CDONTS.NewMail") objMail.From = strSender objMail.To = strReceive objMail.Subject = strSubject objMail.Body = strMessage objMail.Send ' This is the method, actually sends the email ' Done sending the email ' Clean up - empty and destroy all objects Set objMail = Nothing rsOrder.Close Set rsOrder = Nothing cnConnect.Close Set cnConnect = Nothing %>