The Active Server Pages

The Active Server Pages equivalent to the earlier CGI applications, which is shown in Example 2.4, is perhaps the simplest of the three applications. First I'll show you the code, then I'll discuss it a bit.

Example B.4. The ASP Equivalent of the CGI Application

<HTML> <HEAD> <TITLE>Language Preference Storage</TITLE> </HEAD> <BODY> <% ' +-------------------------------------+ ' | Local variable declarations. | ' +-------------------------------------+ Dim strUserName Dim strPrefLang Dim adoCon Dim strSQL ' +-------------------------------------+ ' | Create the ADO Connection object. | ' +-------------------------------------+ Set adoCon = Server.CreateObject("ADODB.Connection") adoCon.Open "LangPref" ' +-------------------------------------+ ' | Retrieve the name and preference | ' | field values from the posted form. | ' +-------------------------------------+ strUserName = Request.Form("UsrName") strPrefLang = Request.Form("ProgLang") ' +-------------------------------------+ ' | Create the INSERT statement. | ' +-------------------------------------+ strSQL = "INSERT INTO LangPrefStorage (Name, " strSQL = strSQL & "LangPref) VALUES ('" strSQL = strSQL & strUserName & "', '" strSQL = strSQL & strPrefLang & "')" ' +-------------------------------------+ ' | Execute the SQL statement and close | ' | the ADO connection. | ' +-------------------------------------+ adoCon.Execute strSQL adoCon.Close %> <H1>Thank you, <%=strUserName%>.</h1> Click <A HREF = '/~wsdocs/langform/formsample.htm'> ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.