You are on page 1of 7

CHAPTER 8 - CODING

The website code has been linked with the database using ASP VBScript. The database consists of the users Login ID, Password, other registration details and the users current Balance. Linking Code for Registration form: <%@LANGUAGE="VBSCRIPT"%> <!--#include file="Connections/regform.asp" --> <% Dim MM_editAction MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")) If (Request.QueryString <> "") Then MM_editAction = MM_editAction Server.HTMLEncode(Request.QueryString) End If ' boolean to abort record edit Dim MM_abortEdit MM_abortEdit = false %> <% ' *** Redirect if username exists MM_flag = "MM_insert" If (CStr(Request(MM_flag)) <> "") Then Dim MM_rsKey Dim MM_rsKey_cmd MM_dupKeyRedirect = "register.asp" MM_dupKeyUsernameValue = CStr(Request.Form("Username")) Set MM_rsKey_cmd = Server.CreateObject ("ADODB.Command") MM_rsKey_cmd.ActiveConnection = MM_regform_STRING MM_rsKey_cmd.CommandText = "SELECT Username FROM Accounts WHERE Username = ?" MM_rsKey_cmd.Prepared = true

&

"?"

&

MM_rsKey_cmd.Parameters.Append MM_rsKey_cmd.CreateParameter("param1", MM_dupKeyUsernameValue) ' adVarChar Set MM_rsKey = MM_rsKey_cmd.Execute

200,

1,

255,

If Not MM_rsKey.EOF Or Not MM_rsKey.BOF Then ' the username was found - can not add the requested username MM_qsChar = "?" If (InStr(1, MM_dupKeyRedirect, "?") >= 1) Then MM_qsChar = "&" MM_dupKeyRedirect = MM_dupKeyRedirect & MM_qsChar & "requsername=" & MM_dupKeyUsernameValue Response.Redirect(MM_dupKeyRedirect) End If MM_rsKey.Close End If %> <% ' IIf implementation Function MM_IIf(condition, ifTrue, ifFalse) If condition = "" Then MM_IIf = ifFalse Else MM_IIf = ifTrue End If End Function %> <% If (CStr(Request("MM_insert")) = "form1") Then If (Not MM_abortEdit) Then ' execute the insert Dim MM_editCmd Set MM_editCmd = Server.CreateObject ("ADODB.Command") MM_editCmd.ActiveConnection = MM_regform_STRING MM_editCmd.CommandText = "INSERT INTO Accounts (Name_User, Username, Password, Age, Gender, City, [E-mail]) VALUES (?, ?, ?, ?, ?, ?, ?)" MM_editCmd.Prepared = true MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 202, 1, 255, Request.Form("Name_User")) ' adVarWChar

MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 202, 1, 255, Request.Form("Username")) ' adVarWChar MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 202, 1, 255, Request.Form("Password")) ' adVarWChar MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 5, 1, -1, MM_IIF(Request.Form("Age"), Request.Form("Age"), null)) ' adDouble MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 202, 1, 255, Request.Form("Gender")) ' adVarWChar MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 202, 1, 255, Request.Form("City")) ' adVarWChar MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 202, 1, 255, Request.Form("Email")) ' adVarWChar MM_editCmd.Execute MM_editCmd.ActiveConnection.Close ' append the query string to the redirect URL Dim MM_editRedirectUrl MM_editRedirectUrl = "success.html" If (Request.QueryString <> "") Then If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then MM_editRedirectUrl = MM_editRedirectUrl & "?" Request.QueryString Else MM_editRedirectUrl = MM_editRedirectUrl & "&" Request.QueryString End If End If Response.Redirect(MM_editRedirectUrl) End If End If %>

&

&

Linking code for Login page: <%@LANGUAGE="VBSCRIPT"%> <!--#include file="Connections/regform.asp" --> <% ' *** Validate request to log in to this site. MM_LoginAction = Request.ServerVariables("URL") If Request.QueryString <> "" Then MM_LoginAction = MM_LoginAction + "?" +Server.HTMLEncode(Request.QueryString) MM_valUsername = CStr(Request.Form("username")) If MM_valUsername <> "" Then Dim MM_fldUserAuthorization Dim MM_redirectLoginSuccess Dim MM_redirectLoginFailed Dim MM_loginSQL Dim MM_rsUser Dim MM_rsUser_cmd MM_fldUserAuthorization = "" MM_redirectLoginSuccess = "expman.asp" MM_redirectLoginFailed = "loginpw.asp" MM_loginSQL = "SELECT Username, Password" If MM_fldUserAuthorization <> "" Then MM_loginSQL = MM_loginSQL & "," &MM_fldUserAuthorization MM_loginSQL = MM_loginSQL & " FROM Accounts WHERE Username = ? ANDPassword = ?" Set MM_rsUser_cmd = Server.CreateObject ("ADODB.Command") MM_rsUser_cmd.ActiveConnection = MM_regform_STRING MM_rsUser_cmd.CommandText = MM_loginSQL MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param1", 200,1, 255, MM_valUsername) ' adVarChar MM_rsUser_cmd.Parameters.Append MM_rsUser_cmd.CreateParameter("param2", 200,1, 255, Request.Form("pw")) ' adVarChar MM_rsUser_cmd.Prepared = true Set MM_rsUser = MM_rsUser_cmd.Execute If Not MM_rsUser.EOF Or Not MM_rsUser.BOF Then ' username and password match - this is a valid user

Session("MM_Username") = MM_valUsername If (MM_fldUserAuthorization <> "") Then Session("MM_UserAuthorization") =CStr(MM_rsUser.Fields.Item(MM_fldUserAuthorization).Value) Else Session("MM_UserAuthorization") = "" End If If CStr(Request.QueryString("accessdenied")) <> "" And false Then MM_redirectLoginSuccess = Request.QueryString("accessdenied") End If MM_rsUser.Close Response.Redirect(MM_redirectLoginSuccess) End If MM_rsUser.Close Response.Redirect(MM_redirectLoginFailed) End If %>

Figure 1 AUTO LOAN CALCULATOR

Figure 2 - Homepage

Figure 3 Compound Interest Calculator

Figure 4 Registration Form

Figure 5 Simple Calculator

You might also like