Insert Part 2 - Sample ASP Files Insert (Part 2) Motes...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon
1 Sample ASP Files – Insert (Part 2) Mote’s Notes 4/20/2011 Insert2.asp This example allows the user to provide information about a new family member. The ASP script validates the following conditions: 1. An employee must be selected from the drop-down list (foreign key) 2. FID must be non-blank, with proper format and unique (primary key) 3. FirstName must have at least two characters 4. LastName must have at least two characters 5. A relationship must be selected 6. Gender must be selected 7. If spouse, then different gender and non-bigamist 8. DOB must be a non-blank, valid date Insert2.asp The code for the first page is fairly straight forward. It just provides textboxes, drop-down lists and radio buttons for the information about the new family member. The Insert button (Type=Submit) passes the user’s input values to the next page. The Reset button (Type=Reset) erases the user’s input values.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 Insert2-Step2.asp <html> <head> <title>Insert 2</title> <link rel=stylesheet type='text/css' href='MyStyle.css'> </head> <!--#include file="MyInfo.asp" --> <!--#include file="MyLibrary.asp" --> <body> <% Response.Write("<h2>Insert 2: New Family Member</h2>") ' Fetch user input from previous page SelectedEID=Request.Form("EID") SelectedFID=CleanString(Replace(Request.Form("FID")," ","")) SelectedFirstName=CleanString(Request.Form("FirstName")) SelectedLastName=CleanString(Request.Form("LastName")) SelectedRelationship=Request.Form("Relationship") SelectedGender=Request.Form("Gender") SelectedDOB=CleanString(Request.Form("DOB")) ' Restrict maximum length of character input SelectedFID=Left(SelectedFID,20) SelectedFirstName=Left(SelectedFirstName,20) SelectedLastName=Left(SelectedLastName,30) ' Open connection to back-end SQL Server database Set conn=Server.CreateObject("ADODB.Connection") conn.CommandTimeout=15 conn.ConnectionTimeout=15 conn.Open BackEnd ' Validate user input Errors=0 ErrorMessage="" ' Validation: EID (non-blank) If Len(SelectedEID)=0 Then Errors=Errors+1 ErrorMessage=ErrorMessage & "The employee EID cannot be blank.<br>" End If ' Validation: FID (length of 3-20, A-Z for first character and A-Z/0-9 for other characters, unique) If Len(SelectedFID)<3 Then Errors=Errors+1 ErrorMessage=ErrorMessage & "The FID must have at least three characters.<br>" Else LegalFID=True C=LCase(Left(SelectedFID,1)) If C<"a" Or C>"z" Then LegalFID=False For P=2 To Len(SelectedFID) C=LCase(Mid(SelectedFID,P,1)) If (C<"a" Or C>"z") And (C<"0" Or C>"9") Then LegalFID=False Next
Background image of page 2
3 If LegalFID=False Then Errors=Errors+1 ErrorMessage=ErrorMessage & "The FID must have A-Z for the first character and A-Z or 0-9 for the others.<br>" Else ' Lookup FID in tblFamily (PK cannot already exist) sql="SELECT FID FROM tblFamily WHERE FID='" & SelectedFID & "'" Set rst=Server.CreateObject("ADODB.Recordset") rst.Open sql, conn If Not rst.EOF Then Errors=Errors+1 ErrorMessage=ErrorMessage & "The FID (" & SelectedFID & ") already exists in tblFamily.<br>" End If rst.Close
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 12

Insert Part 2 - Sample ASP Files Insert (Part 2) Motes...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online